1. Dmitri Lebedev
  2. fastdev-django

Wiki

Clone wiki

fastdev-django / Home

На русском

Contents

Fast Development Setup for Django

This project is a template for fast creation and development of Django websites. It contains all the tools that I know that allow fast coding, debugging and quality control.

When you add packages to buildout.cfg to be used in your project, any collaborator will get them just by running buildout script. No need to compare packages setups and versions, no need to use virtualenv.

With this setup, right away you have

  • extensions and a better shell
  • debugging tools (PuDB, Werkzeug, Debug Toolbar)
  • fast templating tools (HAML, SASS)
  • code quality tools (pyflakes, pep8)
  • useful packages (reversion, tastypie, annoying)

Credits for the initial contents of this package go to:

Installation

Install the following libraries in your system:

  sudo apt-get install libxslt-dev python-dev libpq-dev rubygems make openjdk-6-jre-headless --no-install-recommends

If your OS is not Debian/Ubuntu/Mint, copy the names of these libraries and install them with your package manager.

Clone the project and disconnect from this repo:

    hg clone https://hg.bitbucket.org/siberiano/fastdev-django yourproject
    rm yourproject/.hg/hgrc

See also instructions for CoffeeScript.

Usage

    cd yourproject
    make run

Changed packages in buildout.cfg? Updated django.po in locales? Just stop the server and do make run again. The make shell_plus command is also smart and can re-build bin/django should you change the dependencies in buildout.cfg.

Read "Makefile and Less Keyboard Banging in Shell" for more information.

Important: in this environment, use bin/django instead of manage.py. It's a script, assembled by buildout, that connects the project environment packages.

Requirements

  • Python 2.5+
  • Ruby 1.8+ (for Sass)
  • A database of choice

All the other packages are bundled in the buildout script.

Packages

bootstrap.py

Installs zc.buildout script.

IPython and django-extensions

A better Python shell with code completion and scripting. The extensions package adds shell_plus command that runs IPython. There's a shortcut for it:

    make shell_plus

PuDB

A debugging environment for Python, which looks like the good old QBasic or Borland IDEs from the '80-s.

To use it, add this line in the code where you need to debug:

    import pudb; pudb.set_trace()

django-debug-toolbar

A toolbar that is embed into pages that shows you the list of rendered templates and their contexts. Enable its middleware and see a clickable label on the right in pages.

HamlPy

An elegant markup language that transforms into HTML. HamlPy implements HAML and a similar notation for Django template language:

    - extends 'base.html'
    - load i18n
    - block body
        %h1
            - trans 'Hello'
        .items_effects
            %ul.items
                - for item in menu
                    %li.item
                        %a{'href': "{% url item.get_absolute_url %}",
                            'title': "{{ item.title }}"}= item.name
                        %br
                        = item.description

        .footer
            - trans 'See you'

Django Compressor and Sass

Compressor can be used to transform and compress CSS and JS on the fly. Here it is used to convert SASS stylesheets in valid CSS. Usage (Haml notation):

Template:

    - compress css
        %link{'href': '{{ STATIC_URL }}css/screen.sass',
              'rel': 'stylesheet', 'type': 'text/sass',
              'media': 'screen,projection'}
    - endcompress

Sass stylesheet screen.sass:

    @mixin border-radius ($radii)
        -webkit-border-radius: $radii
        -moz-border-radius: $radii
        -ms-border-radius: $radii
        -o-border-radius: $radii
        border-radius: $radii


    .button
        background: #88f
        +border-radius(1.5em)  // will expand in rules for all vendors

A not included feature: it can parse script tags in the page, open the JS files, minify them and pack into one single file.

CoffeeScript

If you want to use CoffeeScript, do the following:

  • edit Makefile and uncomment the line run: bin/coffee
  • set USE_COFFEE_SCRIPT = True in settings.py
  • if you use Ubuntu, make sure curl is installed (by default it is not):
    sudo apt-get install curl

You DON'T NEED Node.js, nor npm for this project to run CoffeeScript. Buildout will install them automatically. This makes it easier to deploy in web hosting.

WSGI

In the bin folder, <settings name>.wsgi script will be created. (django and prod, as in buildout.cfg.) Connect your Apache or Nginx to this wsgi file.

To update WSGI script (after adding packages to buildout.cfg), just run make bin/django.

Updated