Tag Archives: eclipse

Configuring PyDev to work with Django

Django is the most widely used if not the most popular web framework among those available for python. Have a look at this report by Jacob Kaplan-Moss the co-creator of Django, to get an idea about the current standing of Django among the community.

One disadvantage for Django is the lack of IDE support it has. Here it holds a clear disadvantage against it’s rival web frameworks such as Ruby on Rails. Wing IDE looks impressive but is not free. I wasn’t much impressed with Komodo and it is not free either. The best bet seams to be Netbeans 7 which promises to have good python support. Hopefully it would have satisfactory Django support as well. Currently netbeans is having a python plugin that is still in beta stage. The best alternative for me as of now is PyDev which I have been using with python for sometime now. Here I will explain how to configure PyDev to work with Django.

1.) First download and install Django
2.) Add Django source folder to PYTHONPATH in pydev

  • Go to windows > preferences
  • In the opended dialog choose interpreter-python
  • Here under python interpreter a python interpreter should be available. If not add one by clicking new
  • In System PYTHONPATH add the downloaded source folder of Django by clicking New Folder

3.) Create a new pydev project.

  • Go to file > new > pydev project
  • Enter project name, path and importantly make sure the option ‘create default src folder and add it to PYTHONPATH?’ is choosen. This is easiest way or you can manually add the source folder of the new project to PYTHONPATH by going to File > properties > PYTHONPATH

4.) Start a new Django project

  • Open a new console from the Operating System(console support inside pydev is avialable but is not very satisfactory)
  • Navigate to the newly create src folder inside the pydev project
  • type django-admin.py startproject ‘sitename’ (sitename should be the name of your project). This how a new project is started in Django

If your projects name is mysite the folder structure should be as follows

Now pydev should be configured to work with Django. All the python feature that pydev supports should be now working with Django as well.

The standard features of a modern IDE works beautifully with pydev for Django but there are some major drawbacks. Django template tags are not supported in pydev. Also the console support inside pydev is not impressive. So for now I am forced to use pydev for Django coding, the OS console for giving Django commands and nothing for Django templates.