/django-project-skeleton

A basic scaffold for Django projects

Primary LanguageJavaScript

Django Skeleton

What is a Django skeleton

It's a basic structure which can serve as a base for your Django projects.

Requirements

  • Django 1.3
  • Linux OS

The included directories

  • project - the source code
    • contains all the Django custom applications and settings
    • "project/apps" hosts the custom applications
    • "project/settings" includes the settings for various environments.
    • "project/settings/settings.py" is the file created by the "django-admin.py" tool, the rest of the settings file will import/extend this one.
    • the code from "ipy_user_conf.py" will import all the models when one executes "python manage.py shell" and "ipython" is available
    • "manage.py" must receive the "--settings" argument (please see the usage below)
  • static - the Django's STATIC_ROOT directory
  • media - the Django's MEDIA_ROOT directory
  • env - virtualenv or buildout environment files
  • help - files related to the project, tutorials, photoshop files, etc
  • setup - files necessary to setup the project inside various environments
  • logs - the logs

Optional directories

  • database - this is the parent location of your sqlite database, if case

Principles of this file layout

  • all project files are placed under the same parent
  • keep the project's files in a logical and easy to find structure
  • isolate the environment files so they don't mix with the project
  • easy to decide which directories are to be kept on GIT

Goodies included

  • YUI reset and fonts CSS is being used
  • a basic CSS file built with lesscss.org
  • the base template is using a grid layout based on YUI Grids

Setup the project with virtualenv and pip

  • $ cd /project_name
  • $ git clone git@github.com:florentin/django-skeleton.git .
  • $ virtualenv env --no-site-packages
  • $ source ./env/bin/activate
  • $ mkdir -p database
  • $ pip install -r ./setup/requirements/production.txt
  • $ pip install -r ./setup/requirements/development.txt

Setup the database

  • $ cd /project_name/
  • $ source ./env/bin/activate
  • $ python ./project/manage.py syncdb --settings=settings.development --noinput
  • $ python ./project/manage.py createsuperuser --settings=settings.development --email=admin@admin.com --username=admin
  • $ Password: admin

Start the lightweight development server included with Django

  • $ cd /project_name/
  • $ source ./env/bin/activate
  • $ python ./project/manage.py runserver --settings=settings.development --nostatic
  • or the hard way:
  • $ export PYTHONPATH="./project:${PYTHONPATH}"; export PYTHONPATH="./project/apps:${PYTHONPATH}"; export DJANGO_SETTINGS_MODULE=settings.development; django-admin.py runserver --nostatic

Aliases

You have probably noticed the long line needed to run the commands though the "manage.py". One solution is to create a bash function in .bash_aliases:

dj() { python ./project/manage.py $@ --settings=settings.development; }

Usage:

$ dj runserver --nostatic