.. _django: ====================== Django, the Good Parts ====================== The `Django docs `_ are the best way to learn about Django. These aren't your normal docs. They're useful. Read through the `overview `_, go through the `tutorial `_, or jump into some other part that interests you. My awesomebar loves these pages: * `Querysets `_ * `Model Fields `_ * `Caching `_ * `View Shortcuts `_ * `Testing `_ * `Urls `_ * `Forms `_ I'm not going to go into detail on anything that's covered in the docs, since they do it better. CSRF ---- In Django 1.2, `csrf `_ was improved by embedding ``{% csrf_token %}`` inside forms instead of using middleware to rewrite HTML strings. But since we're using Jinja for templating, that doesn't work. Instead, use :: {{ csrf() }} inside templates to embed the CSRF token Django expects. See :src:`apps/admin/templates/admin/flagged_addon_list.html` for an example. Testing ------- Print it out and read it before you go to bed: http://docs.djangoproject.com/en/dev/topics/testing/ Don't bother with the doctests stuff, we won't use those. We'll write lots of unit tests and make heavy use of the :mod:`test client `. See more in :ref:`testing`. Best Practices -------------- This slide deck has a fantastic overview: http://media.b-list.org/presentations/2008/djangocon/reusable_apps.pdf The basic layout for Django is to have a bunch of little apps that work together to form a site. The thing that brings these apps together is a "project", which holds the top-level settings, url routing, and not much else. The project tells Django what apps you're using so it knows what models to use, but any other Python packages can be imported at will. We like importing things. Since we're going to have a lot of apps, we're putting them in the /apps directory, but some namespace trickery lets us import our packages without the ``apps.`` prefix. If you're adding a new app with models or template tags, add it to ``INSTALLED_APPS`` so Django loads the model and Jinja loads the template extensions. You can find lots of goodies on http://www.b-list.org/weblog/categories/django/. Migrations ---------- We're going to use `South `_. Here's the `Quick Start Guide `_, the `tutorial `__, and the rest of the `South docs `_.