Busy making things: tinycast, github, links, photos, @mc.

Django Gotchas

Posted: July 18th, 2005 | Author: | Filed under: Django, Open Source, Projects, Python | 23 Comments »

I know that a lot of these things will get ironed out or explained more clearly once the platform matures and more people start using it, but here are some tips for early Django adopters trying to get through the tutorials:

  1. Don’t name your project test. I know it sounds like a good idea now. I did the same. Trust me though, at the beginning of Tutorial 2 you’ll start kicking yourself when you run in to namespace collisions with the test module. In order to make this warning a bit more abstract, you’re best off not naming your project anything that is a Python module in the Python Standard Library
  2. Your project directory should be somewhere in your Python Path. Under Linux your best bet is to set the PYTHONPATH environment variable. Here’s the gotcha, if your project is in /path/to/project, you actually want to set your PYTHONPATH variable to /path/to. On a per-session basis you can do this by doing something like export PYTHONPATH=/path/to
  3. In order to really use django-admin.py as often as you’re going to, you really want to symlink it to /bin or /usr/bin. For me (again, under Ubuntu having checked out Django via Subversion), ln -s /usr/lib/python2.4/site-packages/django/bin/django-admin.py /usr/bin/django-admin.py did the trick.
  4. Really pay attention to the install instructions and make sure you symlink your django install to /usr/lib/python/site-packages correctly.
  5. I’m still dealing with the newbie cookie authentication bug that tends to creep up partway through the second tutorial, but I was able to get the admin login to pop up by using the following settings for Apache2 and mod_python (with special thanks to #django and the Django on OSX installation guide):
    <location /admin/>
            SetHandler mod_python
            PythonHandler django.core.handler
            PythonPath sys.path+['/home/mcroydon/django']
            SetEnv DJANGO_SETTINGS_MODULE proj.settings.admin
            PythonDebug On
    </location>

    The PythonPath to the directory containing your project is again quite critical. This is where the test collision will show up if you’ve been foolish enough to name your project test. Make sure that DJANGO_SETTINGS_MODULE points to your project. This worked perfectly for me under Ubuntu Hoary, but YMMV. PythonDebug On is your friend here and turns a plain jane 500 error into a traceback.

Gotchas like these are going to have to be minimized in order to not scare away newbies and also enable that “running start” feeling that you get with Rails. I’m sure that a few of these are mitigated by setup.py in the tarball and the rest should be made a lot easier once WSGI support is added (and I’m glad to hear that adding a built-in server is on the list somewhere) should take care of the rest.

I do have to say that so far (gotchas aside) I’m really impressed with the platform. It’s great to be able to work with the Python interpreter to flush out some test data (you can do similar things with the Ruby interpreter with Rails, but Python is my native language). I also got warm fuzzies when someone asked if there was a mail module for Django. Heck, Python has an awesome standard library, why not use it?

Thanks again to everyone in #django on Freenode for all the help and guidance. Now it’s time to get back to that login gotcha.

Note: Django is a moving target right now. Since I wrote this early this morning, support for a standalone server has been added (just after WSGI support was added) and lots of little bugs and niggles are being taken care of as I type.


23 Comments on “Django Gotchas”

  1. 1 Eric Moritz(irc:slashzero) said at 9:06 am on July 18th, 2005:

    Hey, if you update your svn code, you’ll get the WSGI handler. I haven’t tried it yet.

  2. 2 Eric Moritz(irc:slashzero) said at 9:46 am on July 18th, 2005:

    Also I just spoke with Adrian on irc and he said he’s about to finish a development server that can be invoked by typing “django-admin.py startserver” awesome stuff

  3. 3 Matt Croydon said at 11:15 am on July 18th, 2005:

    Sweet! That’s really what it needs. /me does a happy dance.

  4. 4 aaaaaa said at 10:55 pm on June 14th, 2006:

    333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333

  5. 5 Josh said at 6:29 pm on April 12th, 2007:

    I just spent 4 or 5 hours trying to get a Windows Django project moved over to Ubuntu. The tidbit, “Here’s the gotcha, if your project is in /path/to/project, you actually want to set your PYTHONPATH variable to /path/to.” just made the f!@*)&ing thing work!!! They need to add this to the documentation.

    Thank you for your post!!! Now I can go home and get some sleep!

  6. 6 Liana Merete said at 7:09 pm on September 19th, 2007:

    they’ll have you suicidal,suicida. Liana Merete.

  7. 7 Joey Hadassah said at 6:39 pm on October 21st, 2007:

    oh lord my baby your driving me craz. Joey Hadassah.

  8. 8 ecig said at 4:50 am on November 18th, 2010:

    I have been meaning to post something like this on my website and this has given me an idea. Thank you.

  9. 9 rent to own said at 5:29 pm on November 20th, 2010:

    Thanks for the great post! I wouldn’t have discovered this by myself!

  10. 10 Clifford Lengerich said at 10:09 pm on December 9th, 2010:

    I’m still learning from you, while I’m trying to achieve my goals. I certainly love reading all that is written on your website.Keep the stories coming. I enjoyed it

  11. 11 Pour bebe said at 8:46 pm on December 17th, 2010:

    Pour bebe…

    Many thanks for yet another first-rate article. I am always seeking for super helpful hints to recommend to my own readers. Thank you for making this article. It’s exactly what I was searching for. Truly terrific post….

  12. 12 Bali Villas said at 11:33 pm on January 21st, 2011:

    I love the efforts you have put in this, thanks for all the great posts .

  13. 13 buy propecia said at 9:56 pm on January 23rd, 2011:

    You are absolutely right. In it something is and it is excellent idea. I support you.

  14. 14 free movie download said at 12:15 pm on January 27th, 2011:

    i like it Django Gotchas at Matt Croydon::Postneo a little while ago im your rss reader

  15. 15 lbwyTrc said at 12:31 pm on February 1st, 2011:

    FGwESnSx

  16. 16 marusea said at 9:58 am on February 9th, 2011:

    i like it Django Gotchas at Matt Croydon::Postneo now im your rss reader

  17. 17 Angelita Slutsky said at 12:38 am on February 10th, 2011:

    I wish to express thanks to this writer just for rescuing me from such a situation. Right after searching throughout the world wide web and seeing proposals which are not productive, I figured my life was done. Existing devoid of the solutions to the issues you’ve fixed as a result of your main posting is a crucial case, and the kind that would have badly affected my entire career if I had not come across your website. Your personal competence and kindness in handling every aspect was precious. I’m not sure what I would have done if I hadn’t discovered such a step like this. I am able to now relish my future. Thanks for your time very much for this impressive and amazing guide. I won’t be reluctant to endorse your web site to anybody who needs support on this subject.

  18. 18 paketresa said at 9:40 am on February 10th, 2011:

    really like the article that you have written actually. it really is not that easy to discover great stuff to read (you know.. READ and not just browsing through it like some uniterested and flesh eating zombie before going to yet another post to just ignore), so cheers mate for really not wasting my time! 😉

  19. 19 fgheuifi said at 4:02 pm on February 10th, 2011:

    Hey dude, Steve here Keep em coming you do a great job with this blog, inspiring many newbies much like me cant tell you just how much I appreciate whatever you do! Steve

  20. 20 kids-tory-burch-flats said at 4:07 am on February 14th, 2011:

    cheap tory burch shoes …

    As the summer goes, winter comes.You should have some shoes in store. Based on this point, the cheap tory burch shoes Shoes is developing faster and faster. More and more people do online shopping.With so many shoes in it, now I advise you getting a …

  21. 21 TrinaPITTS24 said at 3:49 pm on February 14th, 2011:

    Don’t you recognize that this is high time to get the loan, which will make you dreams real.

  22. 22 Edison Moros said at 10:30 am on February 16th, 2011:

    high book you’ve take in

  23. 23 paketresor phuket said at 1:11 am on February 19th, 2011:

    i’ve begun to visit this cool site a few times now and i have to say that i find it quite exeptional actually. continue doing what you’re doing! =)