Version 4 (modified by Pedro Algarvio <ufs@…>, 19 years ago) ( diff )

--

Don't know why the sh wiki processor ain't workin', maybe the server doesn't have enscript installed, so here's a plain and not that neat view of the script:

#!/bin/bash

# Project Name, for example:
# DJANGO_PROJECT="$(basename `pwd`)"
DJANGO_PROJECT=''

# Django's HTTP server settings
#SERVER_ADDR="10.1.0.1"
#SERVER_PORT="8080"

# Database Settings
DJANGO_DB_NAME="${DJANGO_PROJECT}"
DJANGO_DB_USER=''
DJANGO_DB_PASS=''

# Project's unique ID setting
DJANGO_SECRET_KEY='YOUR_SECRET_UNIQUE_ID_HERE'

# Update our Python path
PYTHONPATH="$(echo $PYTHONPATH):$(dirname `pwd`)"

# Setup DJANGO_SETTINGS_MODULE
DJANGO_SETTINGS_MODULE="${DJANGO_PROJECT}.settings"

# Check argument passed to script, if '-S', it starts Django's HTTP server
if [ "$1" == "-S" ]; then
    # If SERVER_ADDR is not setup, use the default
    if [ -z "${SERVER_ADDR}" ]; then
        SERVER_ADDR="localhost"
    fi
    # If SERVER_PORT is not setup, use the default
    if [ -z "${SERVER_PORT}" ]; then
        SERVER_PORT="8000"
    fi
    # Start the Django's HTTP Server
    django-admin.py runserver ${SERVER_ADDR}:${SERVER_PORT} \
        --settings="${DJANGO_PROJECT}.settings"
fi
#!/bin/bash

# Project Name, for example:
# DJANGO_PROJECT="$(basename `pwd`)"
DJANGO_PROJECT=''

# Django's HTTP server settings
#SERVER_ADDR="10.1.0.1"
#SERVER_PORT="8080"

# Database Settings
DJANGO_DB_NAME="${DJANGO_PROJECT}"
DJANGO_DB_USER=''
DJANGO_DB_PASS=''

# Project's unique ID setting
DJANGO_SECRET_KEY='YOUR_SECRET_UNIQUE_ID_HERE'

# Update our Python path
PYTHONPATH="$(echo $PYTHONPATH):$(dirname `pwd`)"

# Setup DJANGO_SETTINGS_MODULE
DJANGO_SETTINGS_MODULE="${DJANGO_PROJECT}.settings"

# Check argument passed to script, if '-S', it starts Django's HTTP server
if [ "$1" == "-S" ]; then
    # If SERVER_ADDR is not setup, use the default
    if [ -z "${SERVER_ADDR}" ]; then
        SERVER_ADDR="localhost"
    fi
    # If SERVER_PORT is not setup, use the default
    if [ -z "${SERVER_PORT}" ]; then
        SERVER_PORT="8000"
    fi
    # Start the Django's HTTP Server
    django-admin.py runserver ${SERVER_ADDR}:${SERVER_PORT} \
        --settings="${DJANGO_PROJECT}.settings"
fi

To use it, just source it to update environment variables:

source env.sh

To run the server:

./env -S

This is of course, a file that you won't get into your revision control system, it has private data.

Now, on your project's settings.py, you can use(these are just parts of settings.py of couse):

DATABASE_NAME = os.environ['DJANGO_DB_NAME']
DATABASE_USER = os.environ['DJANGO_DB_USER']
DATABASE_PASSWORD = os.environ['DJANGO_DB_PASS']

SECRET_KEY = os.environ['DJANGO_SECRET_KEY']

And now, you can safely commit settings.py to your revision control system without double checking to see if you forgot to delete the private parts.

Note: See TracWiki for help on using the wiki.
Back to Top