About •  Books •  Apps •  Jobs •   Feeds •  Twitter
Login

First things to do on a Django project...

Call them best practices if you like, but here's the things I do when starting a new Django project.

 

So that's the app project. Next let's set up the static content, that's easy:

  • Create a "static" folder. This is where the css, js, img will live.
  • Serve static through the dev server. When it goes live, I leave the content and urls in the same place, but have static overriden at the Apache (or your favourite server) level to serve the static content and not your dev server.

Create a restart script that starts everything cleanly. For me this normally means:

  • drops the database
  • recreates it
  • syncs the database (syncdb), without input
  • creates a superuser, or loads in a fixture with that data
  • loads in the required fixtures

Here's an old one that does that, I've changed the one I use a bit since then, will need to do a new post. Whilst you are quickly iterating this is the best way to go, it keeps it clean and simple. You'll want to use South or django-evolution once it goes live of course.

For each subsequent app (things that have the models that actually do the work) that you create:
  • Create a forms folder add an __init__.py inside it. Forms will live here.
  • Delete models.py and create a models folder. Add an __init__.py inside it. In the __init__.py import each of the modules that you will be adding. Don't forget to add in app_label on your models.
  • Inside the models folder, create a fixtures folder. Guess what goes in here.
  • Create a signals.py. Signal code will go here.
  • Delete views.py and create a views folder.
  • Create a tests folder, add an __init__.py inside it. Tests will live here.
  • Create a template folder. This is where the templates live.
And that's about it. Next to do on the list is to create a paster script that does all this so you don't have to.

 

Comments

There are 1 comment(s).

Good tips (especially for newbies), however I've already discovered this 'things' while working with Django! ;)

https://me.yahoo.com/a/bpYDcuh_tJ8cP6lNsS3Z9ImyEC0BlUH_#32c8b on Sep, 04

Login to add comments