Django tutorials

Favorite Django Tips

April 20th, 2010
A few months ago I found a really useful Stack Overflow Question. Here are my favorites from the answers.

Use render_to decorator instead of render_to_response

This decorator is found in the app django annoying, and is a very nice shortcut for declaring what template a view should render. Instead of returning the response of render_to_response, you just return a python dict which will be used as the template context for the template specified as argument to the @render_to decorator. If anything else than a dict is returned, normal view processing will occur, so this won't break redirects or any other cases where you might return a HttpResponse (for example normal render_to_response code). Read the rest of this entry »

Views in subfolder

April 15th, 2010

If you want to put your views in a subfolder and you are getting an import error, all you have to do is create a blank “__init__.py” file within that subfolder and everything should work fine. :)

Debugging production Django deployment

March 7th, 2010
Deploying Django is a process that can drive one bananas. There are a lot of things to setup to go from your development environment to the production. Aside from the regular hassles - there come special little buggers that can really make you mad. If you ever had problems with 500.html pages, url configurations or import errors - you know what I mean. However it doesn't all have to be that bad. There are quite a few steps you can take early on to minimize the pain. If you do get into trouble - there are some things you can do to debug out of it. Read the rest of this entry »

Override adding plural “s” in django admin

February 26th, 2010

If you have non-english names for your models, they will look bad when django admin tries to make plural out of them by adding “s” in the end. Fortunately it is easy to override by defining “verbose_name_plural” in your model. Here is an example:

1
2
3
4
5
6
class Tag(models.Model):
    class Meta:
        verbose_name_plural = "Tagovi"
 
    ime = models.CharField(max_length="300")
    opis = models.TextField(blank = True)