Django Gotchas


Posted

in

, , ,

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.

Comments

23 responses to “Django Gotchas”

  1. Eric Moritz(irc:slashzero) Avatar

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

  2. Eric Moritz(irc:slashzero) Avatar

    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. Matt Croydon Avatar

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

  4. aaaaaa Avatar

    333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333

  5. Josh Avatar
    Josh

    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. Liana Merete Avatar

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

  7. Joey Hadassah Avatar

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

  8. ecig Avatar

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

  9. rent to own Avatar

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

  10. Clifford Lengerich Avatar

    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. 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. Bali Villas Avatar

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

  13. buy propecia Avatar

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

  14. free movie download Avatar

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

  15. lbwyTrc Avatar

    FGwESnSx

  16. marusea Avatar

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

  17. Angelita Slutsky Avatar

    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. paketresa Avatar

    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. fgheuifi Avatar

    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. 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. TrinaPITTS24 Avatar

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

  22. Edison Moros Avatar

    high book you’ve take in

  23. paketresor phuket Avatar

    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! =)