Book Image

Mastering Django: Core

By : Nigel George
Book Image

Mastering Django: Core

By: Nigel George

Overview of this book

Mastering Django: Core is a completely revised and updated version of the original Django Book, written by Adrian Holovaty and Jacob Kaplan-Moss - the creators of Django. The main goal of this book is to make you a Django expert. By reading this book, you’ll learn the skills needed to develop powerful websites quickly, with code that is clean and easy to maintain. This book is also a programmer’s manual that provides complete coverage of the current Long Term Support (LTS) version of Django. For developers creating applications for commercial and business critical deployments, Mastering Django: Core provides a complete, up-to-date resource for Django 1.8LTS with a stable code-base, security fixes and support out to 2018.
Table of Contents (33 chapters)
Mastering Django: Core
Credits
About the Author
www.PacktPub.com
Preface
Free Chapter
1
Introduction to Django and Getting Started

DJANGO_SETTINGS_MODULE


When you use Django, you have to tell it which settings you're using. Do this by using an environment variable, DJANGO_SETTINGS_MODULE. The value of DJANGO_SETTINGS_MODULE should be in Python path syntax, for example, mysite.settings.

The django-admin utility

When using django-admin, 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 runserver

Example (Windows shell):

set DJANGO_SETTINGS_MODULE=mysite.settings 
django-admin runserver

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

django-admin runserver --settings=mysite.settings

On the server (mod_wsgi)

In your live server environment, you'll need to tell your WSGI application what settings file to use. Do that with os.environ:

import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'

Read Chapter 13, Deploying Django, for more information and other common elements to a Django WSGI application.