Django newbie gotchas

I'm working on a project which makes use of the Django framework. Django is a web framework which abstracts the back-end database away from the python object and view models which use that database. Since (aside for a small netbean project) I've stayed away from web development for several years, I seem to have missed a lot of noise around ASP, Perl and PHP web development. I hope I haven't missed much. From the looks of the internet, It wouldn't surprise me if only half the web-developers out there only understand half of what they know about web development. There is more than a grain of truth in the saying "If cities were built like web sites, the first woodpecker would destroy civilization".

I'm finding Django 1.0 somewhat challenging, but I'm also finding that I can pull off usable web pages and forms without too much trouble. The django documentation is well above average (especially djangobook.com), and the IRC and mailing list communities are active and helpful. I did run into a few gotchas. Here are some of them:

  • Confusing oldforms, newforms and forms. Djangobook Chapter 7 explains this. If you google information on google forms, you might find 'forms' describing complicated pre-0.96 form API. You might find 'newforms' describing the post 0.96 API or you might find 'forms' describing the post Django 1.0 form API (which is almost exactly the same as 0.96 newforms.)
  • Model form weirdness. I got some unexpected results using model forms which I can't explain in detail here. So I decided to code my own forms and do my own mapping between form views and model.
  • settings.py path issues. Django was installed for me on a zone on one of our OpenSolaris servers. I decided to also install django on my opensolaris laptop so I could work with it while I'm offline. It seemed that when my browser was accessing django remotely (served by apache2.2 on the server's zone), I could break things by changing my local settings.py file or other local django python files! It is possible I had one of the settings.py files pointing to the wrong DATABASE_HOST or wrong MEDIA_URL so be careful!
  • Apache/Firefox cache issues: O.K. This one is easy for anyone who has done web development, but I hadn't since the days of netscape and IE in the mid 1990s so I had to remind myself to svcadm restart apache22 and clear the browser cache after every change.
  • Permission issues: This kind of problem should be obvious to old time web jockeys, but what caught me was this. If you're running django, then make a change to settings.py, urls.py or one of your view.py files and that change causes that file to become unreadable, django continues running with the previously loaded version.
  • Debugging:I haven't yet found out how to access stderr and stdout from the python views or attach pdb in such a way that I can access a console and step through the views or models as they are running.
  • Subclassing: I tried to subclass something in my models.py like this:
    
    myclass is defined in models.py
         Elsewhere I try this:
       class mymetaclass(myclass):
             {additional methods} 
    
    This didn't work.

After a bit of frustration getting over the things I didn't know about web development and sql, I'm finding django to be fun to work with, and it's only at version 1.0!

Comments:

Post a Comment:
Comments are closed for this entry.
About

bnitz

Search

Archives
« April 2014
MonTueWedThuFriSatSun
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
    
       
Today