Sophie

Sophie

distrib > Mageia > 6 > armv7hl > media > core-updates > by-pkgid > 65530c6176058f9b54858c3b4f6385e6 > files > 975

python-django-doc-1.8.19-1.mga6.noarch.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml" lang="">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Django settings &#8212; Django 1.8.19 documentation</title>
    
    <link rel="stylesheet" href="../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '1.8.19',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="top" title="Django 1.8.19 documentation" href="../contents.html" />
    <link rel="up" title="Using Django" href="index.html" />
    <link rel="next" title="Signals" href="signals.html" />
    <link rel="prev" title="Serializing Django objects" href="serialization.html" />



 
<script type="text/javascript" src="../templatebuiltins.js"></script>
<script type="text/javascript">
(function($) {
    if (!django_template_builtins) {
       // templatebuiltins.js missing, do nothing.
       return;
    }
    $(document).ready(function() {
        // Hyperlink Django template tags and filters
        var base = "../ref/templates/builtins.html";
        if (base == "#") {
            // Special case for builtins.html itself
            base = "";
        }
        // Tags are keywords, class '.k'
        $("div.highlight\\-html\\+django span.k").each(function(i, elem) {
             var tagname = $(elem).text();
             if ($.inArray(tagname, django_template_builtins.ttags) != -1) {
                 var fragment = tagname.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + tagname + "</a>");
             }
        });
        // Filters are functions, class '.nf'
        $("div.highlight\\-html\\+django span.nf").each(function(i, elem) {
             var filtername = $(elem).text();
             if ($.inArray(filtername, django_template_builtins.tfilters) != -1) {
                 var fragment = filtername.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + filtername + "</a>");
             }
        });
    });
})(jQuery);
</script>


  </head>
  <body role="document">

    <div class="document">
  <div id="custom-doc" class="yui-t6">
    <div id="hd">
      <h1><a href="../index.html">Django 1.8.19 documentation</a></h1>
      <div id="global-nav">
        <a title="Home page" href="../index.html">Home</a>  |
        <a title="Table of contents" href="../contents.html">Table of contents</a>  |
        <a title="Global index" href="../genindex.html">Index</a>  |
        <a title="Module index" href="../py-modindex.html">Modules</a>
      </div>
      <div class="nav">
    &laquo; <a href="serialization.html" title="Serializing Django objects">previous</a>
     |
    <a href="index.html" title="Using Django" accesskey="U">up</a>
   |
    <a href="signals.html" title="Signals">next</a> &raquo;</div>
    </div>

    <div id="bd">
      <div id="yui-main">
        <div class="yui-b">
          <div class="yui-g" id="topics-settings">
            
  <div class="section" id="s-django-settings">
<span id="django-settings"></span><h1>Django settings<a class="headerlink" href="#django-settings" title="Permalink to this headline">¶</a></h1>
<p>A Django settings file contains all the configuration of your Django
installation. This document explains how settings work and which settings are
available.</p>
<div class="section" id="s-the-basics">
<span id="the-basics"></span><h2>The basics<a class="headerlink" href="#the-basics" title="Permalink to this headline">¶</a></h2>
<p>A settings file is just a Python module with module-level variables.</p>
<p>Here are a couple of example settings:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">ALLOWED_HOSTS</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;www.example.com&#39;</span><span class="p">]</span>
<span class="n">DEBUG</span> <span class="o">=</span> <span class="kc">False</span>
<span class="n">DEFAULT_FROM_EMAIL</span> <span class="o">=</span> <span class="s1">&#39;webmaster@example.com&#39;</span>
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">If you set <a class="reference internal" href="../ref/settings.html#std:setting-DEBUG"><code class="xref std std-setting docutils literal"><span class="pre">DEBUG</span></code></a> to <code class="docutils literal"><span class="pre">False</span></code>, you also need to properly set
the <a class="reference internal" href="../ref/settings.html#std:setting-ALLOWED_HOSTS"><code class="xref std std-setting docutils literal"><span class="pre">ALLOWED_HOSTS</span></code></a> setting.</p>
</div>
<p>Because a settings file is a Python module, the following apply:</p>
<ul>
<li><p class="first">It doesn&#8217;t allow for Python syntax errors.</p>
</li>
<li><p class="first">It can assign settings dynamically using normal Python syntax.
For example:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">MY_SETTING</span> <span class="o">=</span> <span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">30</span><span class="p">)]</span>
</pre></div>
</div>
</li>
<li><p class="first">It can import values from other settings files.</p>
</li>
</ul>
</div>
<div class="section" id="s-designating-the-settings">
<span id="s-django-settings-module"></span><span id="designating-the-settings"></span><span id="django-settings-module"></span><h2>Designating the settings<a class="headerlink" href="#designating-the-settings" title="Permalink to this headline">¶</a></h2>
<dl class="envvar">
<dt id="envvar-DJANGO_SETTINGS_MODULE">
<code class="descname">DJANGO_SETTINGS_MODULE</code><a class="headerlink" href="#envvar-DJANGO_SETTINGS_MODULE" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>When you use Django, you have to tell it which settings you&#8217;re using. Do this
by using an environment variable, <code class="docutils literal"><span class="pre">DJANGO_SETTINGS_MODULE</span></code>.</p>
<p>The value of <code class="docutils literal"><span class="pre">DJANGO_SETTINGS_MODULE</span></code> should be in Python path syntax, e.g.
<code class="docutils literal"><span class="pre">mysite.settings</span></code>. Note that the settings module should be on the
Python <a class="reference external" href="http://www.diveintopython.net/getting_to_know_python/everything_is_an_object.html">import search path</a>.</p>
<div class="section" id="s-the-django-admin-utility">
<span id="the-django-admin-utility"></span><h3>The django-admin utility<a class="headerlink" href="#the-django-admin-utility" title="Permalink to this headline">¶</a></h3>
<p>When using <a class="reference internal" href="../ref/django-admin.html"><span class="doc">django-admin</span></a>, you can either set the
environment variable once, or explicitly pass in the settings module each time
you run the utility.</p>
<p>Example (Unix Bash shell):</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">export</span> <span class="n">DJANGO_SETTINGS_MODULE</span><span class="o">=</span><span class="n">mysite</span><span class="o">.</span><span class="n">settings</span>
<span class="n">django</span><span class="o">-</span><span class="n">admin</span> <span class="n">runserver</span>
</pre></div>
</div>
<p>Example (Windows shell):</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="nb">set</span> <span class="n">DJANGO_SETTINGS_MODULE</span><span class="o">=</span><span class="n">mysite</span><span class="o">.</span><span class="n">settings</span>
<span class="n">django</span><span class="o">-</span><span class="n">admin</span> <span class="n">runserver</span>
</pre></div>
</div>
<p>Use the <code class="docutils literal"><span class="pre">--settings</span></code> command-line argument to specify the settings manually:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">django</span><span class="o">-</span><span class="n">admin</span> <span class="n">runserver</span> <span class="o">--</span><span class="n">settings</span><span class="o">=</span><span class="n">mysite</span><span class="o">.</span><span class="n">settings</span>
</pre></div>
</div>
</div>
<div class="section" id="s-on-the-server-mod-wsgi">
<span id="on-the-server-mod-wsgi"></span><h3>On the server (mod_wsgi)<a class="headerlink" href="#on-the-server-mod-wsgi" title="Permalink to this headline">¶</a></h3>
<p>In your live server environment, you&#8217;ll need to tell your WSGI
application what settings file to use. Do that with <code class="docutils literal"><span class="pre">os.environ</span></code>:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">os</span>

<span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s1">&#39;DJANGO_SETTINGS_MODULE&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;mysite.settings&#39;</span>
</pre></div>
</div>
<p>Read the <a class="reference internal" href="../howto/deployment/wsgi/modwsgi.html"><span class="doc">Django mod_wsgi documentation</span></a> for more information and other common
elements to a Django WSGI application.</p>
</div>
</div>
<div class="section" id="s-default-settings">
<span id="default-settings"></span><h2>Default settings<a class="headerlink" href="#default-settings" title="Permalink to this headline">¶</a></h2>
<p>A Django settings file doesn&#8217;t have to define any settings if it doesn&#8217;t need
to. Each setting has a sensible default value. These defaults live in the
module <code class="file docutils literal"><span class="pre">django/conf/global_settings.py</span></code>.</p>
<p>Here&#8217;s the algorithm Django uses in compiling settings:</p>
<ul class="simple">
<li>Load settings from <code class="docutils literal"><span class="pre">global_settings.py</span></code>.</li>
<li>Load settings from the specified settings file, overriding the global
settings as necessary.</li>
</ul>
<p>Note that a settings file should <em>not</em> import from <code class="docutils literal"><span class="pre">global_settings</span></code>, because
that&#8217;s redundant.</p>
<div class="section" id="s-seeing-which-settings-you-ve-changed">
<span id="seeing-which-settings-you-ve-changed"></span><h3>Seeing which settings you&#8217;ve changed<a class="headerlink" href="#seeing-which-settings-you-ve-changed" title="Permalink to this headline">¶</a></h3>
<p>There&#8217;s an easy way to view which of your settings deviate from the default
settings. The command <code class="docutils literal"><span class="pre">python</span> <span class="pre">manage.py</span> <span class="pre">diffsettings</span></code> displays differences
between the current settings file and Django&#8217;s default settings.</p>
<p>For more, see the <a class="reference internal" href="../ref/django-admin.html#django-admin-diffsettings"><code class="xref std std-djadmin docutils literal"><span class="pre">diffsettings</span></code></a> documentation.</p>
</div>
</div>
<div class="section" id="s-using-settings-in-python-code">
<span id="using-settings-in-python-code"></span><h2>Using settings in Python code<a class="headerlink" href="#using-settings-in-python-code" title="Permalink to this headline">¶</a></h2>
<p>In your Django apps, use settings by importing the object
<code class="docutils literal"><span class="pre">django.conf.settings</span></code>. Example:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">django.conf</span> <span class="k">import</span> <span class="n">settings</span>

<span class="k">if</span> <span class="n">settings</span><span class="o">.</span><span class="n">DEBUG</span><span class="p">:</span>
    <span class="c1"># Do something</span>
</pre></div>
</div>
<p>Note that <code class="docutils literal"><span class="pre">django.conf.settings</span></code> isn&#8217;t a module &#8211; it&#8217;s an object. So
importing individual settings is not possible:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">django.conf.settings</span> <span class="k">import</span> <span class="n">DEBUG</span>  <span class="c1"># This won&#39;t work.</span>
</pre></div>
</div>
<p>Also note that your code should <em>not</em> import from either <code class="docutils literal"><span class="pre">global_settings</span></code> or
your own settings file. <code class="docutils literal"><span class="pre">django.conf.settings</span></code> abstracts the concepts of
default settings and site-specific settings; it presents a single interface.
It also decouples the code that uses settings from the location of your
settings.</p>
</div>
<div class="section" id="s-altering-settings-at-runtime">
<span id="altering-settings-at-runtime"></span><h2>Altering settings at runtime<a class="headerlink" href="#altering-settings-at-runtime" title="Permalink to this headline">¶</a></h2>
<p>You shouldn&#8217;t alter settings in your applications at runtime. For example,
don&#8217;t do this in a view:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">django.conf</span> <span class="k">import</span> <span class="n">settings</span>

<span class="n">settings</span><span class="o">.</span><span class="n">DEBUG</span> <span class="o">=</span> <span class="kc">True</span>   <span class="c1"># Don&#39;t do this!</span>
</pre></div>
</div>
<p>The only place you should assign to settings is in a settings file.</p>
</div>
<div class="section" id="s-security">
<span id="security"></span><h2>Security<a class="headerlink" href="#security" title="Permalink to this headline">¶</a></h2>
<p>Because a settings file contains sensitive information, such as the database
password, you should make every attempt to limit access to it. For example,
change its file permissions so that only you and your Web server&#8217;s user can
read it. This is especially important in a shared-hosting environment.</p>
</div>
<div class="section" id="s-available-settings">
<span id="available-settings"></span><h2>Available settings<a class="headerlink" href="#available-settings" title="Permalink to this headline">¶</a></h2>
<p>For a full list of available settings, see the <a class="reference internal" href="../ref/settings.html"><span class="doc">settings reference</span></a>.</p>
</div>
<div class="section" id="s-creating-your-own-settings">
<span id="creating-your-own-settings"></span><h2>Creating your own settings<a class="headerlink" href="#creating-your-own-settings" title="Permalink to this headline">¶</a></h2>
<p>There&#8217;s nothing stopping you from creating your own settings, for your own
Django apps. Just follow these conventions:</p>
<ul class="simple">
<li>Setting names are in all uppercase.</li>
<li>Don&#8217;t reinvent an already-existing setting.</li>
</ul>
<p>For settings that are sequences, Django itself uses tuples, rather than lists,
but this is only a convention.</p>
</div>
<div class="section" id="s-using-settings-without-setting-django-settings-module">
<span id="s-settings-without-django-settings-module"></span><span id="using-settings-without-setting-django-settings-module"></span><span id="settings-without-django-settings-module"></span><h2>Using settings without setting DJANGO_SETTINGS_MODULE<a class="headerlink" href="#using-settings-without-setting-django-settings-module" title="Permalink to this headline">¶</a></h2>
<p>In some cases, you might want to bypass the <code class="docutils literal"><span class="pre">DJANGO_SETTINGS_MODULE</span></code>
environment variable. For example, if you&#8217;re using the template system by
itself, you likely don&#8217;t want to have to set up an environment variable
pointing to a settings module.</p>
<p>In these cases, you can configure Django&#8217;s settings manually. Do this by
calling:</p>
<dl class="function">
<dt id="django.conf.settings.configure">
<code class="descclassname">django.conf.settings.</code><code class="descname">configure</code>(<em>default_settings</em>, <em>**settings</em>)<a class="headerlink" href="#django.conf.settings.configure" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>Example:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">django.conf</span> <span class="k">import</span> <span class="n">settings</span>

<span class="n">settings</span><span class="o">.</span><span class="n">configure</span><span class="p">(</span><span class="n">DEBUG</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
</pre></div>
</div>
<p>Pass <code class="docutils literal"><span class="pre">configure()</span></code> as many keyword arguments as you&#8217;d like, with each keyword
argument representing a setting and its value. Each argument name should be all
uppercase, with the same name as the settings described above. If a particular
setting is not passed to <code class="docutils literal"><span class="pre">configure()</span></code> and is needed at some later point,
Django will use the default setting value.</p>
<p>Configuring Django in this fashion is mostly necessary &#8211; and, indeed,
recommended &#8211; when you&#8217;re using a piece of the framework inside a larger
application.</p>
<p>Consequently, when configured via <code class="docutils literal"><span class="pre">settings.configure()</span></code>, Django will not
make any modifications to the process environment variables (see the
documentation of <a class="reference internal" href="../ref/settings.html#std:setting-TIME_ZONE"><code class="xref std std-setting docutils literal"><span class="pre">TIME_ZONE</span></code></a> for why this would normally occur). It&#8217;s
assumed that you&#8217;re already in full control of your environment in these
cases.</p>
<div class="section" id="s-custom-default-settings">
<span id="custom-default-settings"></span><h3>Custom default settings<a class="headerlink" href="#custom-default-settings" title="Permalink to this headline">¶</a></h3>
<p>If you&#8217;d like default values to come from somewhere other than
<code class="docutils literal"><span class="pre">django.conf.global_settings</span></code>, you can pass in a module or class that
provides the default settings as the <code class="docutils literal"><span class="pre">default_settings</span></code> argument (or as the
first positional argument) in the call to <code class="docutils literal"><span class="pre">configure()</span></code>.</p>
<p>In this example, default settings are taken from <code class="docutils literal"><span class="pre">myapp_defaults</span></code>, and the
<a class="reference internal" href="../ref/settings.html#std:setting-DEBUG"><code class="xref std std-setting docutils literal"><span class="pre">DEBUG</span></code></a> setting is set to <code class="docutils literal"><span class="pre">True</span></code>, regardless of its value in
<code class="docutils literal"><span class="pre">myapp_defaults</span></code>:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">django.conf</span> <span class="k">import</span> <span class="n">settings</span>
<span class="kn">from</span> <span class="nn">myapp</span> <span class="k">import</span> <span class="n">myapp_defaults</span>

<span class="n">settings</span><span class="o">.</span><span class="n">configure</span><span class="p">(</span><span class="n">default_settings</span><span class="o">=</span><span class="n">myapp_defaults</span><span class="p">,</span> <span class="n">DEBUG</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
</pre></div>
</div>
<p>The following example, which uses <code class="docutils literal"><span class="pre">myapp_defaults</span></code> as a positional argument,
is equivalent:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">settings</span><span class="o">.</span><span class="n">configure</span><span class="p">(</span><span class="n">myapp_defaults</span><span class="p">,</span> <span class="n">DEBUG</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
</pre></div>
</div>
<p>Normally, you will not need to override the defaults in this fashion. The
Django defaults are sufficiently tame that you can safely use them. Be aware
that if you do pass in a new default module, it entirely <em>replaces</em> the Django
defaults, so you must specify a value for every possible setting that might be
used in that code you are importing. Check in
<code class="docutils literal"><span class="pre">django.conf.settings.global_settings</span></code> for the full list.</p>
</div>
<div class="section" id="s-either-configure-or-django-settings-module-is-required">
<span id="either-configure-or-django-settings-module-is-required"></span><h3>Either configure() or DJANGO_SETTINGS_MODULE is required<a class="headerlink" href="#either-configure-or-django-settings-module-is-required" title="Permalink to this headline">¶</a></h3>
<p>If you&#8217;re not setting the <code class="docutils literal"><span class="pre">DJANGO_SETTINGS_MODULE</span></code> environment variable, you
<em>must</em> call <code class="docutils literal"><span class="pre">configure()</span></code> at some point before using any code that reads
settings.</p>
<p>If you don&#8217;t set <code class="docutils literal"><span class="pre">DJANGO_SETTINGS_MODULE</span></code> and don&#8217;t call <code class="docutils literal"><span class="pre">configure()</span></code>,
Django will raise an <code class="docutils literal"><span class="pre">ImportError</span></code> exception the first time a setting
is accessed.</p>
<p>If you set <code class="docutils literal"><span class="pre">DJANGO_SETTINGS_MODULE</span></code>, access settings values somehow, <em>then</em>
call <code class="docutils literal"><span class="pre">configure()</span></code>, Django will raise a <code class="docutils literal"><span class="pre">RuntimeError</span></code> indicating
that settings have already been configured. There is a property just for this
purpose:</p>
<p>For example:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">django.conf</span> <span class="k">import</span> <span class="n">settings</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">settings</span><span class="o">.</span><span class="n">configured</span><span class="p">:</span>
    <span class="n">settings</span><span class="o">.</span><span class="n">configure</span><span class="p">(</span><span class="n">myapp_defaults</span><span class="p">,</span> <span class="n">DEBUG</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
</pre></div>
</div>
<p>Also, it&#8217;s an error to call <code class="docutils literal"><span class="pre">configure()</span></code> more than once, or to call
<code class="docutils literal"><span class="pre">configure()</span></code> after any setting has been accessed.</p>
<p>It boils down to this: Use exactly one of either <code class="docutils literal"><span class="pre">configure()</span></code> or
<code class="docutils literal"><span class="pre">DJANGO_SETTINGS_MODULE</span></code>. Not both, and not neither.</p>
</div>
<div class="section" id="s-calling-django-setup-is-required-for-standalone-django-usage">
<span id="calling-django-setup-is-required-for-standalone-django-usage"></span><h3>Calling <code class="docutils literal"><span class="pre">django.setup()</span></code> is required for &#8220;standalone&#8221; Django usage<a class="headerlink" href="#calling-django-setup-is-required-for-standalone-django-usage" title="Permalink to this headline">¶</a></h3>
<p>If you&#8217;re using components of Django &#8220;standalone&#8221; &#8211; for example, writing a
Python script which loads some Django templates and renders them, or uses the
ORM to fetch some data &#8211; there&#8217;s one more step you&#8217;ll need in addition to
configuring settings.</p>
<p>After you&#8217;ve either set <span class="target" id="index-0"></span><a class="reference internal" href="#envvar-DJANGO_SETTINGS_MODULE"><code class="xref std std-envvar docutils literal"><span class="pre">DJANGO_SETTINGS_MODULE</span></code></a> or called
<code class="docutils literal"><span class="pre">configure()</span></code>, you&#8217;ll need to call <a class="reference internal" href="../ref/applications.html#django.setup" title="django.setup"><code class="xref py py-func docutils literal"><span class="pre">django.setup()</span></code></a> to load your
settings and populate Django&#8217;s application registry. For example:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">django</span>
<span class="kn">from</span> <span class="nn">django.conf</span> <span class="k">import</span> <span class="n">settings</span>
<span class="kn">from</span> <span class="nn">myapp</span> <span class="k">import</span> <span class="n">myapp_defaults</span>

<span class="n">settings</span><span class="o">.</span><span class="n">configure</span><span class="p">(</span><span class="n">default_settings</span><span class="o">=</span><span class="n">myapp_defaults</span><span class="p">,</span> <span class="n">DEBUG</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">django</span><span class="o">.</span><span class="n">setup</span><span class="p">()</span>

<span class="c1"># Now this script or any imported module can use any part of Django it needs.</span>
<span class="kn">from</span> <span class="nn">myapp</span> <span class="k">import</span> <span class="n">models</span>
</pre></div>
</div>
<p>Note that calling <code class="docutils literal"><span class="pre">django.setup()</span></code> is only necessary if your code is truly
standalone. When invoked by your Web server, or through <a class="reference internal" href="../ref/django-admin.html"><span class="doc">django-admin</span></a>, Django will handle this for you.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<dl class="last docutils">
<dt><a class="reference internal" href="../ref/settings.html"><span class="doc">The Settings Reference</span></a></dt>
<dd>Contains the complete list of core and contrib app settings.</dd>
</dl>
</div>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      
        
          <div class="yui-b" id="sidebar">
            
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../contents.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Django settings</a><ul>
<li><a class="reference internal" href="#the-basics">The basics</a></li>
<li><a class="reference internal" href="#designating-the-settings">Designating the settings</a><ul>
<li><a class="reference internal" href="#the-django-admin-utility">The django-admin utility</a></li>
<li><a class="reference internal" href="#on-the-server-mod-wsgi">On the server (mod_wsgi)</a></li>
</ul>
</li>
<li><a class="reference internal" href="#default-settings">Default settings</a><ul>
<li><a class="reference internal" href="#seeing-which-settings-you-ve-changed">Seeing which settings you&#8217;ve changed</a></li>
</ul>
</li>
<li><a class="reference internal" href="#using-settings-in-python-code">Using settings in Python code</a></li>
<li><a class="reference internal" href="#altering-settings-at-runtime">Altering settings at runtime</a></li>
<li><a class="reference internal" href="#security">Security</a></li>
<li><a class="reference internal" href="#available-settings">Available settings</a></li>
<li><a class="reference internal" href="#creating-your-own-settings">Creating your own settings</a></li>
<li><a class="reference internal" href="#using-settings-without-setting-django-settings-module">Using settings without setting DJANGO_SETTINGS_MODULE</a><ul>
<li><a class="reference internal" href="#custom-default-settings">Custom default settings</a></li>
<li><a class="reference internal" href="#either-configure-or-django-settings-module-is-required">Either configure() or DJANGO_SETTINGS_MODULE is required</a></li>
<li><a class="reference internal" href="#calling-django-setup-is-required-for-standalone-django-usage">Calling <code class="docutils literal"><span class="pre">django.setup()</span></code> is required for &#8220;standalone&#8221; Django usage</a></li>
</ul>
</li>
</ul>
</li>
</ul>

  <h3>Browse</h3>
  <ul>
    
      <li>Prev: <a href="serialization.html">Serializing Django objects</a></li>
    
    
      <li>Next: <a href="signals.html">Signals</a></li>
    
  </ul>
  <h3>You are here:</h3>
  <ul>
      <li>
        <a href="../index.html">Django 1.8.19 documentation</a>
        
          <ul><li><a href="index.html">Using Django</a>
        
        <ul><li>Django settings</li></ul>
        </li></ul>
      </li>
  </ul>

  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../_sources/topics/settings.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <form class="search" action="../search.html" method="get">
      <div><input type="text" name="q" /></div>
      <div><input type="submit" value="Go" /></div>
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
              <h3>Last update:</h3>
              <p class="topless">Mar 10, 2018</p>
          </div>
        
      
    </div>

    <div id="ft">
      <div class="nav">
    &laquo; <a href="serialization.html" title="Serializing Django objects">previous</a>
     |
    <a href="index.html" title="Using Django" accesskey="U">up</a>
   |
    <a href="signals.html" title="Signals">next</a> &raquo;</div>
    </div>
  </div>

      <div class="clearer"></div>
    </div>
  </body>
</html>