Tag: tech

Solving “Caught TypeError while rendering: coercing to Unicode: need string or buffer”

hello-sirI’ve been working on a little side project in Django 1.3 and have run into a couple instances in the Django admin where I would get the error:

"Caught TypeError while rendering: coercing to Unicode: need string or buffer"

I did a little Bing-ing (my new default search engine — Google is too big, powerful and, dare I say, evil) and found the following solution from Ryan Brady.

For a Bing search of “django admin ‘Caught TypeError while rendering: coercing to Unicode: need string or buffer‘” there were only 4 results, but lucky for me, Ryan’s solved my problem.

Continue reading »

7 SEO Tips for your Django Site

“It is legal because I wish it.” – Louis XIV, France

Forget content. When it comes to the Internet, Google is king. If you please the king, you can do well.

If you cross the king, your disloyal ass will be thrown into the tower to watch your site wither and die, unless the king deigns to sets you free.

Some of the things that most please the king are “thick” (i.e. not “thin”) content pages, well structured site navigation, and honest links to and from your site.

In building my new site, Wantbox.com, I’ve both pleased and inadvertently crossed the king. The problem with this monarch: he doesn’t speak to his subjects, so if you end up in the tower, you’re never quite sure why.

Your best strategy is to know the rules of the kingdom, and do your best to follow them. Below are some of the best practice, white-hat SEO techniques that I have used to make sure the king stays happy.

Continue reading »

Redirect to the originally requested page after django registration and email activation

redirectFor my newly-launched, django-based social shopping site Wantbox.com, I have implemented @ubernostrum‘s ubiquitous django-registration 0.7 to handle user registrations.

Recently I completed a Wantbox feature that required me to redirect a new user back to their initially requested, authorization-required page after their registration and email activation. Below are the step-by-steps actions I took to accomplish this.

Continue reading »

Configure the output of the Django development server

django-logI recently opened up my home dev server for a closed, friends and family alpha launch of my new commerce/community site Wantbox.com. Now that people besides me are hitting the server, I wanted to see client IP addresses in the dev server output.

Continue reading »

OAuthcalypse Now: Tweeting with Twitter, OAuth and Django

The Twitter OAuthcalypse hit me last week. Back in July, I used Twitter’s basic authentication scheme in a new site I’m working on (wantbox.com) to easily send out tweets via my @wantbox account whenever someone posted a new “want” to the site.

This integration took about 30 minutes to research and implement. All I had to do was put my twitter username and password in my Django project’s settings.py file, pip install the python-twitter app into my virtualenv and then use:

from django.conf import settings
import twitter
api = twitter.Api(username=settings.TWITTER_USERNAME, password=settings.TWITTER_PASSWORD)
api.PostUpdate('Someone in 02481 wants "a home gym" %s' % extra_stuff)

The resulting tweet would appear in my @wantbox stream appearing to come “via API”. Easy-peasy.

Continue reading »

Customizing Django Comments: Remove Unwanted Fields

no-commentI recently added comments to a new Django site that I’m working on. Comments pose an interesting problem as they can have a number of “parents”. In my case, the parent might be a user’s “Want” a respondent’s “Have” or possibly another “Comment.”

In the process of researching the best way to architect Wantbox’s comments app, I read about “polymorphic associations“, “exclusive arcs” and Django’s ContentType framework. Using this knowledge, I contemplated recreating the comment wheel, since I wanted my comment form to just be a simple “Stack Overflow-type” comment-only field and not the larger “WordPress-type” name/email/website/comment.

Continue reading »

Django 1.2 Tutorials: Django by Example

pony-magicLooking for some good Django 1.2 tutorials? Check out Django by Example by “andreai.avk”. I just discovered them myself via the django-users group on googlegroups.com.

When I searched a few months ago for good (and current) Django tutorials, I never ran across this site. Hopefully adding a couple links will help bump it up the Google rankings. The simple blog tutorial is currently ranked #103 for the search “django 1.2 tutorials”, but no other page from the site is in the top 500.

Topics covered include: Django admin customization, comment notification and moderation, thumbnail creation, searching and filtering, and automated testing. Current demos include a To-Do App, a Simple Blog, a Photo Organizing and Sharing App and a Simple Forum.

Let the link juice trickle.

Show a Custom 403 Forbidden Error Page in Django

error_403Creating a custom 404 Page Not Found error page is so easy in Django (all you do is put your own template named “404.html” at the root of your templates directory) that I naturally assumed doing the same for a 403 Forbidden error page would be just as easy. Unfortunately it is not.

After searching around for quite a while last night, I found bits and pieces that I have modified slightly and republished below in a unambiguous step-by-step tutorial (see the “Source and Other Resources” section at the end of the post for a few of the source posts).

Continue reading »

Getting Started with virtualenv (Isolated Python Environments)

virtualenvLike South, virtualenv is a helper utility that I put off using for too long. Looking back, it is so easy to get up and running (just like South, see below) that there is no reason for you to hold off like I did.

In a nutshell, virtualenv is a tool for creating isolated Python environments. This is particularly useful if you host multiple Django projects on a single dev box. As an example, virtualenv allows you to easily work on one site built on Django 1.1 and django-registration 0.7  and another one built on Django 1.2 with django-registration 0.8.

Continue reading »

Getting Started with South (Django Database Migrations)

southIf you have worked on a project in Django, you have undoubtedly discovered that ‘syncdb’ is great at turning your ‘models.py’ files into real database tables but not so great at taking your modified models and altering your database with the new definitions. In fact, the Django documentation is pretty clear about this: “Syncdb will not alter existing tables”.

South is a Django project which solves this problem by providing “consistent, easy-to-use, database-agnostic migrations for Django applications.” Below are the most basic steps for getting South up and running in your project.

Continue reading »

Real Time Analytics