Tool to start Django and Bongo projects

pip install pypeton==0.5.0


Abandoned and replaced with:

An application to bootstrap

Frequently we need to create a Django project from scratch and push it on a production machine. pypeton helps reduce the number of manual steps to achieve this goal.


pip install -e git+git://


pypeton [options] project_name


  --version          show program's version number and exit
  -h, --help         show this help message and exit
  -v, --virtualenv   initialise virtual envirnment
  -s, --subversion   create project in svn style with trunk/tags/branches
  -d DIR, --dir=DIR  base project directory
  -e ENV, --env=ENV  [django]


Most basic project

pypeton my_project

Build out an svn folder structure, insert a django project into trunk, and initialize a virtual environment all in one step.

pypeton -s -v my_project  

Specify a directory other than the present working directory

pypeton -d /path/to/folder  my_project


Add description of project customization:

  • how to define requirements
  • what's in which folder

Installing requirements

The next step is to install the requirements for the project, with these commands:

cd fooapp/trunk
source activate
cd project
./ require

where ./ require is a provided shortcut for pip install -r ../deploy/requirements.txt && pip install -r ../deploy/requirements/development.txt.

Running the project in the browser

The project comes with an empty home-page which can be seen in a web browser by running:

./ syncdb
./ server

and then opening http://localhost:8000/ in a browser window. ./ server is a shortcut provided for the command ./ runserver used frequently to start the local server.

Resetting the database and loading fixtures

The project also comes with an application named initial_data, a model with a fixture to create in the development environment an admin user with password admin and a site called These data can be loaded by running:

./ sync

where ./ sync is a shortcut to:

  • reset the database structure
  • synchronize it again with the latest models
  • optionally reload the fixtures for the specified environment (in this case, users and sites for development)

At this point, Django admin can be accessed by running ./ server again, then logging into with admin/admin (make sure to have "" in the machine hosts file pointing to the localhost).

Creating a new model and application

A new model (e.g., called Picture) can be created with the command:

./sta Picture

which extends the default "./ startapp" command by delivering a coherent file structure and providing two basic views for index and show. To include this model in the application:

  • add 'pictures', to INSTALLED_APPS in settings/, and
  • add (r'^pictures/', include('pictures.urls')) to urlpatterns in
  • run ./ sync to add the model to the database

At this point, all these new views become available:

Customizing the model

The newly created model can be edited at will. For instance, the Picture model can be inherited by django-imagekit's ImageModel in order to have many image-related functions available. For this purpose:

  • add the following lines to deploy/requirements.txt:

    pil                  # to use models.ImageField
    django-imagekit      # to deal with image size, thumbnails
  • run the command ./ require to install the new requirements

  • edit apps/pictures/ to begin as:

    from django.db import models
    from imagekit.models import ImageModel
    class Picture(ImageModel):
        name = models.CharField(max_length=255)
        image = models.ImageField(upload_to='pictures')
        num_views = models.PositiveIntegerField(editable=False, default=0)
        class IKOptions:
            # This inner class is where we define the ImageKit options for the model
            spec_module   = 'pictures.specs'
            cache_dir     = 'cache'
            image_field   = 'image'
            save_count_as = 'num_views'
  • add apps/pictures/ as:

    from imagekit.specs import ImageSpec
    from imagekit import processors
    # first we define our thumbnail resize processor
    class ResizeThumb(processors.Resize):
        width =  20
        height = 20
        crop = True
    # now we can define our thumbnail spec
    class Thumbnail(ImageSpec):
        access_as = 'thumbnail_image'
        pre_cache = True
        processors = [ResizeThumb]
  • change the loop in template/pictures/index.html as:

    {% for picture in pictures %}
        <li><a href={{ picture.get_absolute_url }}>
          {{ }}
          <img src="{{ picture.thumbnail_image.url}}" />
    {% endfor %}
  • add <img src="{{picture.image.url}}" /> to the content in templates/pictures/show.html

At this point, run ./ sync to adjust the database in order the include the Imagekit fields into the Picture table. Then the following views allow to:

Creating fixtures

Whenever the ./ sync command is run, all the data in the database is deleted. The method not to lose data during a synchronization is using fixtures.

For instance, after adding a Picture through the admin interface, this can be stored in a fixture running:

./ dump pictures

where ./ dump is a shortcut for ./ dumpdata to output the data with the right indentation in the specified environment.

At this point, running .syn development again will reset the database and reload the images from the fixtures, without losing any data in the operation.

Storing uploads on a CDN

For local development, storing uploads (such as images) in the same folder as the Django code is fine. But this is not the desired behavior on staging or production machines. Uploads can be easily stored in Rackspace CDN by using django-cumulus:

  • log into Rackspace cloud and create a new container
  • add the following line to deploy/requirements.txt:

    django-cumulus       # to store uploads on CDN
  • run the command ./ require to install the new requirement

  • add the following lines to settings/

    CUMULUS_USERNAME         = '[Your Rackspace Cloud username]'
    CUMULUS_API_KEY          = '[Your Rackspace Cloud API key]'
    CUMULUS_CONTAINER        = '[Your Rackspace Cloud container]'
    CUMULUS_FILTER_LIST      = ['.DS_Store']
    STATIC_URL               = ""

At this point, run ./ sync --settings=settings.staging to set up a database for the staging server (which, for now, is on the same development machine). Since it's a staging server, an admin/admin user will not be created automatically, but prompted, in order to use a valid password.

Then run ./ server --settings=settings.staging to run the server with the staging settings. All the pictures will then be uploaded to the CDN and not to any local folder.

It is also possible to batch upload all the pictures loaded so far in the development machine onto the CDN server that serves the staging environment by running:

./ syncstatic --settings=settings.staging