How do you structure your django projects?

I really love Django. It is extremely easy to get started with, even if you don’t know any Python (I didn’t when I started using Django). It is also very customizable, you can change the entire directory structure if you want to. As a project grows, like the Fyndiq codebase I am currently working on (around 15 000 – 20 000 lines of html/python/css/javascript not counting 3rd party code), you have to restructure a bit to get some order. This is kindof how my current layout looks, but I’m changing it whenever I get better ideas:


apps/
  subsystem1/
    app1/
    app2/
  subsystem2/
    app1/
    app2/
  subsystem3/
    app1/
    app2/
docs/
scripts/
  manage.py
  urls.py
  settings.py
  and so on...
static/
  subsystem1/
    img/
    css/
    js/
  subsystem2/
    img/
    css/
    js/
templates/
  subsystem1/
  subsystem2/
var/
  img/
  log/

I am pretty happy with this. It is nice to have a var/ folder with all data that is not part of a deploy (I simply create soft links from static/ to subdirectories of var/img/). It is also nice to have the templates outside the apps, as I find I often borrow template files between apps. The only thing I am not totally happy with is how each app has its own models, since my apps often use each others models. It would make much more sense to have some kind of centralized models/ folder in the project root, with all database stuff. Haven’t gotten around to fixing that yet though.

  • by the way, have you tried playing w/ google app engine at all?

    we generally like to use lots of files rather than stick everything in views.py, esp. as projects that grow and grow...

Jag spenderar det mesta av min tid med att bygga ett fyndvaruhus på nätet. Detta är min privata blogg som handlar om saker som intresserar mig. Sådana saker berör oftast webb, programmering, vetenskap, böcker, musik eller entreprenörskap. Nå mig på micke at micaelwidell punkt com. Jag finns också på twitter, boktipset, last.fm, facebook, spotify och linkedin. Prenumerera gärna på mina blogginlägg via RSS.


Arkiv: oktober 2011 juli 2011 mars 2011 februari 2011 januari 2011 december 2010 november 2010 oktober 2010 september 2010 juli 2010 juni 2010 maj 2010 april 2010 mars 2010