2007年3月30日 星期五

Django setting

Clipmarks user micmickimo has sent you a clip...

 clipped from www.djangoproject.com

Django settings


The basics

A settings file is just a Python module with module-level variables.

Here are a couple of example settings:

DEBUG = False DEFAULT_FROM_EMAIL = 'webmaster@example.com' TEMPLATE_DIRS = ('/home/templates/mike', '/home/templates/john') 

Because a settings file is a Python module, the following apply:

  • It doesn't allow for Python syntax errors.

  • It can assign settings dynamically using normal Python syntax. For example:

    MY_SETTING = [str(i) for i in range(30)] 
  • It can import values from other settings files.


The django-admin.py utility

When using django-admin.py, you can either set the environment variable once, or explicitly pass in the settings module each time you run the utility.

Example (Unix Bash shell):

export DJANGO_SETTINGS_MODULE=mysite.settings django-admin.py runserver 

Example (Windows shell):

set DJANGO_SETTINGS_MODULE=mysite.settings django-admin.py runserver 

Use the --settings command-line argument to specify the settings manually:

django-admin.py runserver --settings=mysite.settings 

On the server (mod_python)

In your live server environment, you'll need to tell Apache/mod_python which settings file to use. Do that with SetEnv:

<Location "/mysite/">     SetHandler python-program     PythonHandler django.core.handlers.modpython     SetEnv DJANGO_SETTINGS_MODULE mysite.settings </Location> 

Read the Django mod_python documentation for more information.

To see more clips or start creating your own, visit clipmarks.com
Sent with Clipmarks

沒有留言: