Login

Use django-admin.py instead of manage.py

Author:
whiteinge
Posted:
June 13, 2008
Language:
HTML/template
Version:
Not specified
Tags:
bash shell zsh
Score:
0 (after 2 ratings)

A lot of people new to Django don't realize that manage.py is just a wrapper around the django-admin.py script installed with Django and isn't needed.

(You may need to symlink django-admin.py to someplace in your system PATH such as /usr/local/bin.)

The most important thing it does is to set your PYTHONPATH and DJANGO_SETTINGS_MODULE environment variables before calling django-admin.py. Those same settings are needed when you move your site on to a production server like Apache, so it is important to know how they work.

This shell function sets those variables for you. Put it in your .zshrc or bash startup script. It works for both the monolithic project style and the lightweight app style of Django development [1], [2].

This function isn't fancy; drop a comment if you have an improvement. Written for zsh and tested with bash 3.1.17.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# For a monolithic project, just run the function from the project folder.
#
# For a reusable app, run the function from the folder containing the settings
# file, and pass the settings file as an argument.
# E.g. ``djsetup somecoolsite_settings.py``

djsetup()
{
    if [ x"$1" != x ]; then
        export PYTHONPATH=$PWD
        export DJANGO_SETTINGS_MODULE=$(basename $1 .py)
    else
        cd ..
        export PYTHONPATH=$PWD
        export DJANGO_SETTINGS_MODULE=$(basename $OLDPWD).settings
        cd $OLDPWD
    fi
}

More like this

  1. Command Line Script Launcher by dakrauth 6 years, 10 months ago
  2. Digg-style pagination, and retain GET params by hanson2010 2 years, 12 months ago
  3. cron/console bootstrap django by nstrite 7 years, 9 months ago
  4. Autoload Django Models When Using ./manage.py shell by sheats 7 years, 4 months ago
  5. Virtualfish Hook by HubertGrzeskowiak 11 months, 3 weeks ago

Comments

Please login first before commenting.