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 »

Installing Python 2.5 in Fedora 12 for Google App Engine

April 16th, 2010
This stupid install process gets me every time! How do you run Google App Engine which currently requires Python2.5 on a machine that has Python2.6 installed? This also goes for anybody trying to use Django with App-Engine. 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 »

Tips for readable python code

March 2nd, 2010

In this post I will try to explain some tricks I use to make python code more readable. These tips won’t make your code shorter and it won’t be better optimized, it will actually use more memory than before, but it will be much easier to understand and edit for someone else.
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)

django.core.exceptions.ImproperlyConfigured: Error loading psycopg module: No module named psycopg

February 26th, 2010

Well, it seems that you are simply missing Psycopg – PostgreSQL database adapter for Python, you need it to connect to PostgreSQL database.

To install untar file that you downloaded, go inside psycopg2-x.x.x folder and execute

> python setup.py build
> python setup.py install

Reasons why to use Django

February 25th, 2010

First of all, what is Django? Django is high-level Python Web framework that was released under BSD license in 2005. It emphasizes re-usability, rapid development and DRY (don’t repeat yourself) principle.
There are a lot of great web development frameworks avaliable, like Ruby on rails and Codeigniter for PHP that follow same principles so we could say that Django is just another fast development web framework but with different flavor. And this is why I like this flavor best.
Read the rest of this entry »

Python 2.6 – an orphan child

February 11th, 2010
The current dominating version of python is 2.5. Most of the frameworks and vendors have comfortably settled on 2.5. Some of the upcoming technologies will support Python 3 exclusively. That leaves our old friend Python 2.6 out in the cold. Read the rest of this entry »

django-rest or Reviving django-rest-interface

December 23rd, 2009
I have taken it upon myself (which is probably more than I can handle!) to revive the django-rest-interface project. The new project is called simply django-rest and you can find it on Google code here: http://code.google.com/p/django-rest/ Read the rest of this entry »