Login

Use django-admin.py instead of manage.py

Author:
whiteinge
Posted:
June 13, 2008
Language:
HTML/template
Version:
Not specified
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. Bootstrap Accordian by Netplay4 5 years, 11 months ago
  2. Bootstrap theme for django-endless-pagination? by se210 8 years, 11 months ago
  3. Bootstrap theme for django-endless-pagination? by se210 8 years, 11 months ago
  4. Reusable form template with generic view by roldandvg 9 years ago
  5. Pagination Django with Boostrap by guilegarcia 9 years, 2 months ago

Comments

Please login first before commenting.