Django Best Practices

  • I just read Two Scoops of Django and wished I read it when I first started developing Django apps. Highly recommended.

    https://django.2scoops.org/

    HN discussion: http://news.ycombinator.com/item?id=5074026

  • Some more tips to maintain your sanity once you are past the beginner level:

    * Use South before you start deploying

    * Use an automated deployment tool like Fabric or more powerful ones like Chef/Puppet

    * Get a better debugger and other niceties with django-command-extensions

    Of course, a lot more apps can be considered must have depending on what you are working on.

  • I've got to disagree with the chapter about settings files. Instead of maintaining multiple different settings for different environments, make your default settings file pull modifications for each environment from os.environ, e.g.:

      STATIC_URL = os.environ.get('STATIC_URL', '/static/')
    
    This is a lot saner and won't descend into a mess that is keeping multiple settings files around. It's also a lot easier to explain.

  • Using pip the way they recommend is careless. It makes your deployment dependent on: 1. a working network connection and 2. All the remote repositories being up. 3. nobody having messed with the remote repos. The 3. is admittedly less of a concern, but all 3. are beyond your control and re-downloading the dependencies on each install is wasteful.

    Fortunately pip has the --find-links option which, combined with having all dependencies downloaded locally makes it possible to have a fully local install.

  • This is great, I especially like the discussion about Managers which I haven't used before, but I have never been impressed by the technical chops of Smashing Magazine so to see that as an endorsement is actually a bit of a drawback. :/

  • I like the chainable queryset methods.