Bitbucket is a code hosting site with unlimited public and private repositories. We're also free for small teams!

Close

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:

Requirements

  • Python 2.5+
  • rubygems (for Sass)
  • libxml-dev, libxslt-dev
  • Database of your choice
  • Java Runtime (without JDK/GUI)

Install these libraries in Ubuntu with this command:

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

All the other packages are bundled in the buildout script.

Installation

Clone the project:

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

If you want to use CoffeeScript, read section "CoffeeScript" below.

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.

Database

While developing, you may need to quickly recreate the database from scratch and reload fixtures. Fastdev-django has a command for this:

make rebuilddb

It will drop the db and run syncdb again.

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()

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.

Haml

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.

Recent activity

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.