Sophie

Sophie

distrib > Mageia > 6 > i586 > by-pkgid > 65530c6176058f9b54858c3b4f6385e6 > files > 747

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>The staticfiles app &#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="contrib packages" href="index.html" />
    <link rel="next" title="The syndication feed framework" href="syndication.html" />
    <link rel="prev" title="The “sites” framework" href="sites.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 = "../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="sites.html" title="The &amp;#8220;sites&amp;#8221; framework">previous</a>
     |
    <a href="../index.html" title="API Reference" accesskey="U">up</a>
   |
    <a href="syndication.html" title="The syndication feed framework">next</a> &raquo;</div>
    </div>

    <div id="bd">
      <div id="yui-main">
        <div class="yui-b">
          <div class="yui-g" id="ref-contrib-staticfiles">
            
  <div class="section" id="s-module-django.contrib.staticfiles">
<span id="s-the-staticfiles-app"></span><span id="module-django.contrib.staticfiles"></span><span id="the-staticfiles-app"></span><h1>The staticfiles app<a class="headerlink" href="#module-django.contrib.staticfiles" title="Permalink to this headline">¶</a></h1>
<p><code class="docutils literal"><span class="pre">django.contrib.staticfiles</span></code> collects static files from each of your
applications (and any other places you specify) into a single location that
can easily be served in production.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last">For an introduction to the static files app and some usage examples, see
<a class="reference internal" href="../../howto/static-files/index.html"><span class="doc">Managing static files (e.g. images, JavaScript, CSS)</span></a>. For guidelines on deploying static files,
see <a class="reference internal" href="../../howto/static-files/deployment.html"><span class="doc">Deploying static files</span></a>.</p>
</div>
<div class="section" id="s-settings">
<span id="s-staticfiles-settings"></span><span id="settings"></span><span id="staticfiles-settings"></span><h2>Settings<a class="headerlink" href="#settings" title="Permalink to this headline">¶</a></h2>
<p>See <a class="reference internal" href="../settings.html#settings-staticfiles"><span class="std std-ref">staticfiles settings</span></a> for details on the
following settings:</p>
<ul class="simple">
<li><a class="reference internal" href="../settings.html#std:setting-STATIC_ROOT"><code class="xref std std-setting docutils literal"><span class="pre">STATIC_ROOT</span></code></a></li>
<li><a class="reference internal" href="../settings.html#std:setting-STATIC_URL"><code class="xref std std-setting docutils literal"><span class="pre">STATIC_URL</span></code></a></li>
<li><a class="reference internal" href="../settings.html#std:setting-STATICFILES_DIRS"><code class="xref std std-setting docutils literal"><span class="pre">STATICFILES_DIRS</span></code></a></li>
<li><a class="reference internal" href="../settings.html#std:setting-STATICFILES_STORAGE"><code class="xref std std-setting docutils literal"><span class="pre">STATICFILES_STORAGE</span></code></a></li>
<li><a class="reference internal" href="../settings.html#std:setting-STATICFILES_FINDERS"><code class="xref std std-setting docutils literal"><span class="pre">STATICFILES_FINDERS</span></code></a></li>
</ul>
</div>
<div class="section" id="s-management-commands">
<span id="management-commands"></span><h2>Management Commands<a class="headerlink" href="#management-commands" title="Permalink to this headline">¶</a></h2>
<p><code class="docutils literal"><span class="pre">django.contrib.staticfiles</span></code> exposes three management commands.</p>
<div class="section" id="s-collectstatic">
<span id="collectstatic"></span><h3>collectstatic<a class="headerlink" href="#collectstatic" title="Permalink to this headline">¶</a></h3>
<dl class="django-admin">
<dt id="django-admin-collectstatic">
<code class="descname">django-admin collectstatic</code><a class="headerlink" href="#django-admin-collectstatic" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>Collects the static files into <a class="reference internal" href="../settings.html#std:setting-STATIC_ROOT"><code class="xref std std-setting docutils literal"><span class="pre">STATIC_ROOT</span></code></a>.</p>
<p>Duplicate file names are by default resolved in a similar way to how template
resolution works: the file that is first found in one of the specified
locations will be used. If you&#8217;re confused, the <a class="reference internal" href="#django-admin-findstatic"><code class="xref std std-djadmin docutils literal"><span class="pre">findstatic</span></code></a> command
can help show you which files are found.</p>
<p>On subsequent <code class="docutils literal"><span class="pre">collectstatic</span></code> runs (if <code class="docutils literal"><span class="pre">STATIC_ROOT</span></code> isn&#8217;t empty), files
are copied only if they have a modified timestamp greater than the timestamp of
the file in <code class="docutils literal"><span class="pre">STATIC_ROOT</span></code>. Therefore if you remove an application from
<a class="reference internal" href="../settings.html#std:setting-INSTALLED_APPS"><code class="xref std std-setting docutils literal"><span class="pre">INSTALLED_APPS</span></code></a>, it&#8217;s a good idea to use the <a class="reference internal" href="#django-admin-option---clear"><code class="xref std std-djadminopt docutils literal"><span class="pre">--clear</span></code></a>
option in order to remove stale static files.</p>
<p>Files are searched by using the <a class="reference internal" href="../settings.html#std:setting-STATICFILES_FINDERS"><code class="xref std std-setting docutils literal"><span class="pre">enabled</span> <span class="pre">finders</span></code></a>. The default is to look in all locations defined in
<a class="reference internal" href="../settings.html#std:setting-STATICFILES_DIRS"><code class="xref std std-setting docutils literal"><span class="pre">STATICFILES_DIRS</span></code></a> and in the <code class="docutils literal"><span class="pre">'static'</span></code> directory of apps
specified by the <a class="reference internal" href="../settings.html#std:setting-INSTALLED_APPS"><code class="xref std std-setting docutils literal"><span class="pre">INSTALLED_APPS</span></code></a> setting.</p>
<p>The <a class="reference internal" href="#django-admin-collectstatic"><code class="xref std std-djadmin docutils literal"><span class="pre">collectstatic</span></code></a> management command calls the
<a class="reference internal" href="#django.contrib.staticfiles.storage.StaticFilesStorage.post_process" title="django.contrib.staticfiles.storage.StaticFilesStorage.post_process"><code class="xref py py-meth docutils literal"><span class="pre">post_process()</span></code></a>
method of the <a class="reference internal" href="../settings.html#std:setting-STATICFILES_STORAGE"><code class="xref std std-setting docutils literal"><span class="pre">STATICFILES_STORAGE</span></code></a> after each run and passes
a list of paths that have been found by the management command. It also
receives all command line options of <a class="reference internal" href="#django-admin-collectstatic"><code class="xref std std-djadmin docutils literal"><span class="pre">collectstatic</span></code></a>. This is used
by the <a class="reference internal" href="#django.contrib.staticfiles.storage.CachedStaticFilesStorage" title="django.contrib.staticfiles.storage.CachedStaticFilesStorage"><code class="xref py py-class docutils literal"><span class="pre">CachedStaticFilesStorage</span></code></a>
by default.</p>
<p>By default, collected files receive permissions from
<a class="reference internal" href="../settings.html#std:setting-FILE_UPLOAD_PERMISSIONS"><code class="xref std std-setting docutils literal"><span class="pre">FILE_UPLOAD_PERMISSIONS</span></code></a> and collected directories receive permissions
from <a class="reference internal" href="../settings.html#std:setting-FILE_UPLOAD_DIRECTORY_PERMISSIONS"><code class="xref std std-setting docutils literal"><span class="pre">FILE_UPLOAD_DIRECTORY_PERMISSIONS</span></code></a>. If you would like different
permissions for these files and/or directories, you can subclass either of the
<a class="reference internal" href="#staticfiles-storages"><span class="std std-ref">static files storage classes</span></a> and specify the
<code class="docutils literal"><span class="pre">file_permissions_mode</span></code> and/or <code class="docutils literal"><span class="pre">directory_permissions_mode</span></code> parameters,
respectively. For example:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">django.contrib.staticfiles</span> <span class="k">import</span> <span class="n">storage</span>

<span class="k">class</span> <span class="nc">MyStaticFilesStorage</span><span class="p">(</span><span class="n">storage</span><span class="o">.</span><span class="n">StaticFilesStorage</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;file_permissions_mode&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="mo">0o640</span>
        <span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;directory_permissions_mode&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="mo">0o760</span>
        <span class="nb">super</span><span class="p">(</span><span class="n">MyStaticFilesStorage</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
</pre></div>
</div>
<p>Then set the <a class="reference internal" href="../settings.html#std:setting-STATICFILES_STORAGE"><code class="xref std std-setting docutils literal"><span class="pre">STATICFILES_STORAGE</span></code></a> setting to
<code class="docutils literal"><span class="pre">'path.to.MyStaticFilesStorage'</span></code>.</p>
<div class="versionadded">
<span class="title">New in Django 1.7:</span> <p>The ability to override <code class="docutils literal"><span class="pre">file_permissions_mode</span></code> and
<code class="docutils literal"><span class="pre">directory_permissions_mode</span></code> is new in Django 1.7.  Previously the file
permissions always used <a class="reference internal" href="../settings.html#std:setting-FILE_UPLOAD_PERMISSIONS"><code class="xref std std-setting docutils literal"><span class="pre">FILE_UPLOAD_PERMISSIONS</span></code></a> and the directory
permissions always used <a class="reference internal" href="../settings.html#std:setting-FILE_UPLOAD_DIRECTORY_PERMISSIONS"><code class="xref std std-setting docutils literal"><span class="pre">FILE_UPLOAD_DIRECTORY_PERMISSIONS</span></code></a>.</p>
</div>
<p>Some commonly used options are:</p>
<dl class="django-admin-option">
<dt id="django-admin-option---noinput">
<code class="descname">--noinput</code><code class="descclassname"></code><a class="headerlink" href="#django-admin-option---noinput" title="Permalink to this definition">¶</a></dt>
<dd><p>Do NOT prompt the user for input of any kind.</p>
</dd></dl>

<dl class="django-admin-option">
<dt id="django-admin-option--i">
<code class="descname">-i</code><code class="descclassname"> &lt;pattern&gt;</code><a class="headerlink" href="#django-admin-option--i" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="django-admin-option">
<dt id="django-admin-option---ignore">
<code class="descname">--ignore</code><code class="descclassname"> &lt;pattern&gt;</code><a class="headerlink" href="#django-admin-option---ignore" title="Permalink to this definition">¶</a></dt>
<dd><p>Ignore files or directories matching this glob-style pattern. Use multiple
times to ignore more.</p>
</dd></dl>

<dl class="django-admin-option">
<dt id="django-admin-option--n">
<code class="descname">-n</code><code class="descclassname"></code><a class="headerlink" href="#django-admin-option--n" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="django-admin-option">
<dt id="django-admin-option---dry-run">
<code class="descname">--dry-run</code><code class="descclassname"></code><a class="headerlink" href="#django-admin-option---dry-run" title="Permalink to this definition">¶</a></dt>
<dd><p>Do everything except modify the filesystem.</p>
</dd></dl>

<dl class="django-admin-option">
<dt id="django-admin-option--c">
<code class="descname">-c</code><code class="descclassname"></code><a class="headerlink" href="#django-admin-option--c" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="django-admin-option">
<dt id="django-admin-option---clear">
<code class="descname">--clear</code><code class="descclassname"></code><a class="headerlink" href="#django-admin-option---clear" title="Permalink to this definition">¶</a></dt>
<dd><p>Clear the existing files before trying to copy or link the original file.</p>
</dd></dl>

<dl class="django-admin-option">
<dt id="django-admin-option--l">
<code class="descname">-l</code><code class="descclassname"></code><a class="headerlink" href="#django-admin-option--l" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="django-admin-option">
<dt id="django-admin-option---link">
<code class="descname">--link</code><code class="descclassname"></code><a class="headerlink" href="#django-admin-option---link" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a symbolic link to each file instead of copying.</p>
</dd></dl>

<dl class="django-admin-option">
<dt id="django-admin-option---no-post-process">
<code class="descname">--no-post-process</code><code class="descclassname"></code><a class="headerlink" href="#django-admin-option---no-post-process" title="Permalink to this definition">¶</a></dt>
<dd><p>Don&#8217;t call the
<a class="reference internal" href="#django.contrib.staticfiles.storage.StaticFilesStorage.post_process" title="django.contrib.staticfiles.storage.StaticFilesStorage.post_process"><code class="xref py py-meth docutils literal"><span class="pre">post_process()</span></code></a>
method of the configured <a class="reference internal" href="../settings.html#std:setting-STATICFILES_STORAGE"><code class="xref std std-setting docutils literal"><span class="pre">STATICFILES_STORAGE</span></code></a> storage backend.</p>
</dd></dl>

<dl class="django-admin-option">
<dt id="django-admin-option---no-default-ignore">
<code class="descname">--no-default-ignore</code><code class="descclassname"></code><a class="headerlink" href="#django-admin-option---no-default-ignore" title="Permalink to this definition">¶</a></dt>
<dd><p>Don&#8217;t ignore the common private glob-style patterns <code class="docutils literal"><span class="pre">'CVS'</span></code>, <code class="docutils literal"><span class="pre">'.*'</span></code>
and <code class="docutils literal"><span class="pre">'*~'</span></code>.</p>
</dd></dl>

<p>For a full list of options, refer to the commands own help by running:</p>
<div class="highlight-console"><div class="highlight"><pre><span></span><span class="gp">$</span> python manage.py collectstatic --help
</pre></div>
</div>
</div>
<div class="section" id="s-findstatic">
<span id="findstatic"></span><h3>findstatic<a class="headerlink" href="#findstatic" title="Permalink to this headline">¶</a></h3>
<dl class="django-admin">
<dt id="django-admin-findstatic">
<code class="descname">django-admin findstatic</code><a class="headerlink" href="#django-admin-findstatic" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>Searches for one or more relative paths with the enabled finders.</p>
<p>For example:</p>
<div class="highlight-console"><div class="highlight"><pre><span></span><span class="gp">$</span> python manage.py findstatic css/base.css admin/js/core.js
<span class="go">Found &#39;css/base.css&#39; here:</span>
<span class="go">  /home/special.polls.com/core/static/css/base.css</span>
<span class="go">  /home/polls.com/core/static/css/base.css</span>
<span class="go">Found &#39;admin/js/core.js&#39; here:</span>
<span class="go">  /home/polls.com/src/django/contrib/admin/media/js/core.js</span>
</pre></div>
</div>
<p>By default, all matching locations are found. To only return the first match
for each relative path, use the <code class="docutils literal"><span class="pre">--first</span></code> option:</p>
<div class="highlight-console"><div class="highlight"><pre><span></span><span class="gp">$</span> python manage.py findstatic css/base.css --first
<span class="go">Found &#39;css/base.css&#39; here:</span>
<span class="go">  /home/special.polls.com/core/static/css/base.css</span>
</pre></div>
</div>
<p>This is a debugging aid; it&#8217;ll show you exactly which static file will be
collected for a given path.</p>
<p>By setting the <a class="reference internal" href="../django-admin.html#django-admin-option---verbosity"><code class="xref std std-djadminopt docutils literal"><span class="pre">--verbosity</span></code></a> flag to 0, you can suppress the extra
output and just get the path names:</p>
<div class="highlight-console"><div class="highlight"><pre><span></span><span class="gp">$</span> python manage.py findstatic css/base.css --verbosity 0
<span class="go">/home/special.polls.com/core/static/css/base.css</span>
<span class="go">/home/polls.com/core/static/css/base.css</span>
</pre></div>
</div>
<p>On the other hand, by setting the <a class="reference internal" href="../django-admin.html#django-admin-option---verbosity"><code class="xref std std-djadminopt docutils literal"><span class="pre">--verbosity</span></code></a> flag to 2, you can
get all the directories which were searched:</p>
<div class="highlight-console"><div class="highlight"><pre><span></span><span class="gp">$</span> python manage.py findstatic css/base.css --verbosity 2
<span class="go">Found &#39;css/base.css&#39; here:</span>
<span class="go">  /home/special.polls.com/core/static/css/base.css</span>
<span class="go">  /home/polls.com/core/static/css/base.css</span>
<span class="go">Looking in the following locations:</span>
<span class="go">  /home/special.polls.com/core/static</span>
<span class="go">  /home/polls.com/core/static</span>
<span class="go">  /some/other/path/static</span>
</pre></div>
</div>
<div class="versionadded">
<span class="title">New in Django 1.7:</span> <p>The additional output of which directories were searched was added.</p>
</div>
</div>
<div class="section" id="s-runserver">
<span id="s-staticfiles-runserver"></span><span id="runserver"></span><span id="staticfiles-runserver"></span><h3>runserver<a class="headerlink" href="#runserver" title="Permalink to this headline">¶</a></h3>
<dl class="django-admin">
<dt id="django-admin-runserver">
<code class="descname">django-admin runserver</code><a class="headerlink" href="#django-admin-runserver" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>Overrides the core <a class="reference internal" href="../django-admin.html#django-admin-runserver"><code class="xref std std-djadmin docutils literal"><span class="pre">runserver</span></code></a> command if the <code class="docutils literal"><span class="pre">staticfiles</span></code> app
is <a class="reference internal" href="../settings.html#std:setting-INSTALLED_APPS"><code class="xref std std-setting docutils literal"><span class="pre">installed</span></code></a> and adds automatic serving of static
files and the following new options.</p>
<dl class="django-admin-option">
<dt id="django-admin-option---nostatic">
<code class="descname">--nostatic</code><code class="descclassname"></code><a class="headerlink" href="#django-admin-option---nostatic" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>Use the <code class="docutils literal"><span class="pre">--nostatic</span></code> option to disable serving of static files with the
<a class="reference internal" href="#"><span class="doc">staticfiles</span></a> app entirely. This option is
only available if the <a class="reference internal" href="#"><span class="doc">staticfiles</span></a> app is
in your project&#8217;s <a class="reference internal" href="../settings.html#std:setting-INSTALLED_APPS"><code class="xref std std-setting docutils literal"><span class="pre">INSTALLED_APPS</span></code></a> setting.</p>
<p>Example usage:</p>
<div class="highlight-console"><div class="highlight"><pre><span></span><span class="go">django-admin runserver --nostatic</span>
</pre></div>
</div>
<dl class="django-admin-option">
<dt id="django-admin-option---insecure">
<code class="descname">--insecure</code><code class="descclassname"></code><a class="headerlink" href="#django-admin-option---insecure" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>Use the <code class="docutils literal"><span class="pre">--insecure</span></code> option to force serving of static files with the
<a class="reference internal" href="#"><span class="doc">staticfiles</span></a> app even if the <a class="reference internal" href="../settings.html#std:setting-DEBUG"><code class="xref std std-setting docutils literal"><span class="pre">DEBUG</span></code></a>
setting is <code class="docutils literal"><span class="pre">False</span></code>. By using this you acknowledge the fact that it&#8217;s
<strong>grossly inefficient</strong> and probably <strong>insecure</strong>. This is only intended for
local development, should <strong>never be used in production</strong> and is only
available if the <a class="reference internal" href="#"><span class="doc">staticfiles</span></a> app is
in your project&#8217;s <a class="reference internal" href="../settings.html#std:setting-INSTALLED_APPS"><code class="xref std std-setting docutils literal"><span class="pre">INSTALLED_APPS</span></code></a> setting. <a class="reference internal" href="../django-admin.html#django-admin-runserver"><code class="xref std std-djadmin docutils literal"><span class="pre">runserver</span></code></a>
<code class="docutils literal"><span class="pre">--insecure</span></code> doesn&#8217;t work with
<a class="reference internal" href="#django.contrib.staticfiles.storage.CachedStaticFilesStorage" title="django.contrib.staticfiles.storage.CachedStaticFilesStorage"><code class="xref py py-class docutils literal"><span class="pre">CachedStaticFilesStorage</span></code></a>.</p>
<p>Example usage:</p>
<div class="highlight-console"><div class="highlight"><pre><span></span><span class="go">django-admin runserver --insecure</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="s-storages">
<span id="s-staticfiles-storages"></span><span id="storages"></span><span id="staticfiles-storages"></span><h2>Storages<a class="headerlink" href="#storages" title="Permalink to this headline">¶</a></h2>
<div class="section" id="s-staticfilesstorage">
<span id="staticfilesstorage"></span><h3>StaticFilesStorage<a class="headerlink" href="#staticfilesstorage" title="Permalink to this headline">¶</a></h3>
<dl class="class">
<dt id="django.contrib.staticfiles.storage.StaticFilesStorage">
<em class="property">class </em><code class="descclassname">storage.</code><code class="descname">StaticFilesStorage</code><a class="headerlink" href="#django.contrib.staticfiles.storage.StaticFilesStorage" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>A subclass of the <a class="reference internal" href="../files/storage.html#django.core.files.storage.FileSystemStorage" title="django.core.files.storage.FileSystemStorage"><code class="xref py py-class docutils literal"><span class="pre">FileSystemStorage</span></code></a>
storage backend that uses the <a class="reference internal" href="../settings.html#std:setting-STATIC_ROOT"><code class="xref std std-setting docutils literal"><span class="pre">STATIC_ROOT</span></code></a> setting as the base
file system location and the <a class="reference internal" href="../settings.html#std:setting-STATIC_URL"><code class="xref std std-setting docutils literal"><span class="pre">STATIC_URL</span></code></a> setting respectively
as the base URL.</p>
<dl class="method">
<dt id="django.contrib.staticfiles.storage.StaticFilesStorage.post_process">
<code class="descclassname">storage.StaticFilesStorage.</code><code class="descname">post_process</code>(<em>paths</em>, <em>**options</em>)<a class="headerlink" href="#django.contrib.staticfiles.storage.StaticFilesStorage.post_process" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>This method is called by the <a class="reference internal" href="#django-admin-collectstatic"><code class="xref std std-djadmin docutils literal"><span class="pre">collectstatic</span></code></a> management command
after each run and gets passed the local storages and paths of found
files as a dictionary, as well as the command line options.</p>
<p>The <a class="reference internal" href="#django.contrib.staticfiles.storage.CachedStaticFilesStorage" title="django.contrib.staticfiles.storage.CachedStaticFilesStorage"><code class="xref py py-class docutils literal"><span class="pre">CachedStaticFilesStorage</span></code></a>
uses this behind the scenes to replace the paths with their hashed
counterparts and update the cache appropriately.</p>
</div>
<div class="section" id="s-manifeststaticfilesstorage">
<span id="manifeststaticfilesstorage"></span><h3>ManifestStaticFilesStorage<a class="headerlink" href="#manifeststaticfilesstorage" title="Permalink to this headline">¶</a></h3>
<div class="versionadded">
<span class="title">New in Django 1.7.</span> </div>
<dl class="class">
<dt id="django.contrib.staticfiles.storage.ManifestStaticFilesStorage">
<em class="property">class </em><code class="descclassname">storage.</code><code class="descname">ManifestStaticFilesStorage</code><a class="headerlink" href="#django.contrib.staticfiles.storage.ManifestStaticFilesStorage" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>A subclass of the <a class="reference internal" href="#django.contrib.staticfiles.storage.StaticFilesStorage" title="django.contrib.staticfiles.storage.StaticFilesStorage"><code class="xref py py-class docutils literal"><span class="pre">StaticFilesStorage</span></code></a>
storage backend which stores the file names it handles by appending the MD5
hash of the file&#8217;s content to the filename. For example, the file
<code class="docutils literal"><span class="pre">css/styles.css</span></code> would also be saved as <code class="docutils literal"><span class="pre">css/styles.55e7cbb9ba48.css</span></code>.</p>
<p>The purpose of this storage is to keep serving the old files in case some
pages still refer to those files, e.g. because they are cached by you or
a 3rd party proxy server. Additionally, it&#8217;s very helpful if you want to
apply <a class="reference external" href="https://developer.yahoo.com/performance/rules.html#expires">far future Expires headers</a> to the deployed files to speed up the
load time for subsequent page visits.</p>
<p>The storage backend automatically replaces the paths found in the saved
files matching other saved files with the path of the cached copy (using
the <a class="reference internal" href="#django.contrib.staticfiles.storage.StaticFilesStorage.post_process" title="django.contrib.staticfiles.storage.StaticFilesStorage.post_process"><code class="xref py py-meth docutils literal"><span class="pre">post_process()</span></code></a>
method). The regular expressions used to find those paths
(<code class="docutils literal"><span class="pre">django.contrib.staticfiles.storage.HashedFilesMixin.patterns</span></code>)
by default covers the <a class="reference external" href="http://www.w3.org/TR/CSS2/cascade.html#at-import">&#64;import</a> rule and <a class="reference external" href="http://www.w3.org/TR/CSS2/syndata.html#uri">url()</a> statement of <a class="reference external" href="http://www.w3.org/Style/CSS/">Cascading
Style Sheets</a>. For example, the <code class="docutils literal"><span class="pre">'css/styles.css'</span></code> file with the
content</p>
<div class="highlight-css+django"><div class="highlight"><pre><span></span><span class="k">@import</span> <span class="nt">url</span><span class="o">(</span><span class="s2">&quot;../admin/css/base.css&quot;</span><span class="o">)</span><span class="p">;</span>
</pre></div>
</div>
<p>would be replaced by calling the <a class="reference internal" href="../files/storage.html#django.core.files.storage.Storage.url" title="django.core.files.storage.Storage.url"><code class="xref py py-meth docutils literal"><span class="pre">url()</span></code></a>
method of the <code class="docutils literal"><span class="pre">ManifestStaticFilesStorage</span></code> storage backend, ultimately
saving a <code class="docutils literal"><span class="pre">'css/styles.55e7cbb9ba48.css'</span></code> file with the following
content:</p>
<div class="highlight-css+django"><div class="highlight"><pre><span></span><span class="k">@import</span> <span class="nt">url</span><span class="o">(</span><span class="s2">&quot;../admin/css/base.27e20196a850.css&quot;</span><span class="o">)</span><span class="p">;</span>
</pre></div>
</div>
<p>To enable the <code class="docutils literal"><span class="pre">ManifestStaticFilesStorage</span></code> you have to make sure the
following requirements are met:</p>
<ul class="simple">
<li>the <a class="reference internal" href="../settings.html#std:setting-STATICFILES_STORAGE"><code class="xref std std-setting docutils literal"><span class="pre">STATICFILES_STORAGE</span></code></a> setting is set to
<code class="docutils literal"><span class="pre">'django.contrib.staticfiles.storage.ManifestStaticFilesStorage'</span></code></li>
<li>the <a class="reference internal" href="../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">False</span></code></li>
<li>you use the <code class="docutils literal"><span class="pre">staticfiles</span></code> <a class="reference internal" href="#std:templatetag-staticfiles-static"><code class="xref std std-ttag docutils literal"><span class="pre">static</span></code></a> template
tag to refer to your static files in your templates</li>
<li>you&#8217;ve collected all your static files by using the
<a class="reference internal" href="#django-admin-collectstatic"><code class="xref std std-djadmin docutils literal"><span class="pre">collectstatic</span></code></a> management command</li>
</ul>
<p>Since creating the MD5 hash can be a performance burden to your website
during runtime, <code class="docutils literal"><span class="pre">staticfiles</span></code> will automatically store the mapping with
hashed names for all processed files in a file called <code class="docutils literal"><span class="pre">staticfiles.json</span></code>.
This happens once when you run the <a class="reference internal" href="#django-admin-collectstatic"><code class="xref std std-djadmin docutils literal"><span class="pre">collectstatic</span></code></a> management
command.</p>
<p>Due to the requirement of running <a class="reference internal" href="#django-admin-collectstatic"><code class="xref std std-djadmin docutils literal"><span class="pre">collectstatic</span></code></a>, this storage
typically shouldn&#8217;t be used when running tests as <code class="docutils literal"><span class="pre">collectstatic</span></code> isn&#8217;t run
as part of the normal test setup. During testing, ensure that the
<a class="reference internal" href="../settings.html#std:setting-STATICFILES_STORAGE"><code class="xref std std-setting docutils literal"><span class="pre">STATICFILES_STORAGE</span></code></a> setting is set to something else like
<code class="docutils literal"><span class="pre">'django.contrib.staticfiles.storage.StaticFilesStorage'</span></code> (the default).</p>
<dl class="method">
<dt id="django.contrib.staticfiles.storage.ManifestStaticFilesStorage.file_hash">
<code class="descclassname">storage.ManifestStaticFilesStorage.</code><code class="descname">file_hash</code>(<em>name</em>, <em>content=None</em>)<a class="headerlink" href="#django.contrib.staticfiles.storage.ManifestStaticFilesStorage.file_hash" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>The method that is used when creating the hashed name of a file.
Needs to return a hash for the given file name and content.
By default it calculates a MD5 hash from the content&#8217;s chunks as
mentioned above. Feel free to override this method to use your own
hashing algorithm.</p>
</div>
<div class="section" id="s-cachedstaticfilesstorage">
<span id="cachedstaticfilesstorage"></span><h3>CachedStaticFilesStorage<a class="headerlink" href="#cachedstaticfilesstorage" title="Permalink to this headline">¶</a></h3>
<dl class="class">
<dt id="django.contrib.staticfiles.storage.CachedStaticFilesStorage">
<em class="property">class </em><code class="descclassname">storage.</code><code class="descname">CachedStaticFilesStorage</code><a class="headerlink" href="#django.contrib.staticfiles.storage.CachedStaticFilesStorage" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p><code class="docutils literal"><span class="pre">CachedStaticFilesStorage</span></code> is a similar class like the
<a class="reference internal" href="#django.contrib.staticfiles.storage.ManifestStaticFilesStorage" title="django.contrib.staticfiles.storage.ManifestStaticFilesStorage"><code class="xref py py-class docutils literal"><span class="pre">ManifestStaticFilesStorage</span></code></a> class
but uses Django&#8217;s <a class="reference internal" href="../../topics/cache.html"><span class="doc">caching framework</span></a> for storing the
hashed names of processed files instead of a static manifest file called
<code class="docutils literal"><span class="pre">staticfiles.json</span></code>. This is mostly useful for situations in which you don&#8217;t
have access to the file system.</p>
<p>If you want to override certain options of the cache backend the storage uses,
simply specify a custom entry in the <a class="reference internal" href="../settings.html#std:setting-CACHES"><code class="xref std std-setting docutils literal"><span class="pre">CACHES</span></code></a> setting named
<code class="docutils literal"><span class="pre">'staticfiles'</span></code>. It falls back to using the <code class="docutils literal"><span class="pre">'default'</span></code> cache backend.</p>
</div>
</div>
<div class="section" id="s-template-tags">
<span id="template-tags"></span><h2>Template tags<a class="headerlink" href="#template-tags" title="Permalink to this headline">¶</a></h2>
<div class="section" id="s-static">
<span id="static"></span><h3>static<a class="headerlink" href="#static" title="Permalink to this headline">¶</a></h3>
<p id="std:templatetag-staticfiles-static">Uses the configured <a class="reference internal" href="../settings.html#std:setting-STATICFILES_STORAGE"><code class="xref std std-setting docutils literal"><span class="pre">STATICFILES_STORAGE</span></code></a> storage to create the
full URL for the given relative path, e.g.:</p>
<div class="highlight-html+django"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">load</span> <span class="nv">static</span> <span class="nv">from</span> <span class="nv">staticfiles</span> <span class="cp">%}</span>
<span class="p">&lt;</span><span class="nt">img</span> <span class="na">src</span><span class="o">=</span><span class="s">&quot;</span><span class="cp">{%</span> <span class="k">static</span> <span class="s2">&quot;images/hi.jpg&quot;</span> <span class="cp">%}</span><span class="s">&quot;</span> <span class="na">alt</span><span class="o">=</span><span class="s">&quot;Hi!&quot;</span> <span class="p">/&gt;</span>
</pre></div>
</div>
<p>The previous example is equal to calling the <code class="docutils literal"><span class="pre">url</span></code> method of an instance of
<a class="reference internal" href="../settings.html#std:setting-STATICFILES_STORAGE"><code class="xref std std-setting docutils literal"><span class="pre">STATICFILES_STORAGE</span></code></a> with <code class="docutils literal"><span class="pre">&quot;images/hi.jpg&quot;</span></code>. This is especially
useful when using a non-local storage backend to deploy files as documented
in <a class="reference internal" href="../../howto/static-files/deployment.html#staticfiles-from-cdn"><span class="std std-ref">Serving static files from a cloud service or CDN</span></a>.</p>
<p>If you&#8217;d like to retrieve a static URL without displaying it, you can use a
slightly different call:</p>
<div class="highlight-html+django"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">load</span> <span class="nv">static</span> <span class="nv">from</span> <span class="nv">staticfiles</span> <span class="cp">%}</span>
<span class="cp">{%</span> <span class="k">static</span> <span class="s2">&quot;images/hi.jpg&quot;</span> <span class="k">as</span> <span class="nv">myphoto</span> <span class="cp">%}</span>
<span class="p">&lt;</span><span class="nt">img</span> <span class="na">src</span><span class="o">=</span><span class="s">&quot;</span><span class="cp">{{</span> <span class="nv">myphoto</span> <span class="cp">}}</span><span class="s">&quot;</span> <span class="na">alt</span><span class="o">=</span><span class="s">&quot;Hi!&quot;</span> <span class="p">/&gt;</span>
</pre></div>
</div>
<div class="admonition-using-jinja2-templates admonition">
<p class="first admonition-title">Using Jinja2 templates?</p>
<p class="last">See <a class="reference internal" href="../../topics/templates.html#django.template.backends.jinja2.Jinja2" title="django.template.backends.jinja2.Jinja2"><code class="xref py py-class docutils literal"><span class="pre">django.template.backends.jinja2.Jinja2</span></code></a> for information on
using the <code class="docutils literal"><span class="pre">static</span></code> tag with Jinja2.</p>
</div>
</div>
</div>
<div class="section" id="s-finders-module">
<span id="finders-module"></span><h2>Finders Module<a class="headerlink" href="#finders-module" title="Permalink to this headline">¶</a></h2>
<p><code class="docutils literal"><span class="pre">staticfiles</span></code> finders has a <code class="docutils literal"><span class="pre">searched_locations</span></code> attribute which is a list
of directory paths in which the finders searched. Example usage:</p>
<div class="highlight-console"><div class="highlight"><pre><span></span><span class="go">from django.contrib.staticfiles import finders</span>

<span class="go">result = finders.find(&#39;css/base.css&#39;)</span>
<span class="go">searched_locations = finders.searched_locations</span>
</pre></div>
</div>
<div class="versionadded">
<span class="title">New in Django 1.7.</span> </div>
<p>The <code class="docutils literal"><span class="pre">searched_locations</span></code> attribute was added.</p>
</div>
<div class="section" id="s-other-helpers">
<span id="other-helpers"></span><h2>Other Helpers<a class="headerlink" href="#other-helpers" title="Permalink to this headline">¶</a></h2>
<p>There are a few other helpers outside of the
<a class="reference internal" href="#module-django.contrib.staticfiles" title="django.contrib.staticfiles: An app for handling static files."><code class="xref py py-mod docutils literal"><span class="pre">staticfiles</span></code></a> app to work with static
files:</p>
<ul class="simple">
<li>The <a class="reference internal" href="../templates/api.html#django.template.context_processors.static" title="django.template.context_processors.static"><code class="xref py py-func docutils literal"><span class="pre">django.template.context_processors.static()</span></code></a> context processor
which adds <a class="reference internal" href="../settings.html#std:setting-STATIC_URL"><code class="xref std std-setting docutils literal"><span class="pre">STATIC_URL</span></code></a> to every template context rendered
with <a class="reference internal" href="../templates/api.html#django.template.RequestContext" title="django.template.RequestContext"><code class="xref py py-class docutils literal"><span class="pre">RequestContext</span></code></a> contexts.</li>
<li>The builtin template tag <a class="reference internal" href="../templates/builtins.html#std:templatetag-static"><code class="xref std std-ttag docutils literal"><span class="pre">static</span></code></a> which takes a path and
urljoins it with the static prefix <a class="reference internal" href="../settings.html#std:setting-STATIC_URL"><code class="xref std std-setting docutils literal"><span class="pre">STATIC_URL</span></code></a>.</li>
<li>The builtin template tag <a class="reference internal" href="../templates/builtins.html#std:templatetag-get_static_prefix"><code class="xref std std-ttag docutils literal"><span class="pre">get_static_prefix</span></code></a> which populates a
template variable with the static prefix <a class="reference internal" href="../settings.html#std:setting-STATIC_URL"><code class="xref std std-setting docutils literal"><span class="pre">STATIC_URL</span></code></a> to be
used as a variable or directly.</li>
<li>The similar template tag <a class="reference internal" href="../templates/builtins.html#std:templatetag-get_media_prefix"><code class="xref std std-ttag docutils literal"><span class="pre">get_media_prefix</span></code></a> which works like
<a class="reference internal" href="../templates/builtins.html#std:templatetag-get_static_prefix"><code class="xref std std-ttag docutils literal"><span class="pre">get_static_prefix</span></code></a> but uses <a class="reference internal" href="../settings.html#std:setting-MEDIA_URL"><code class="xref std std-setting docutils literal"><span class="pre">MEDIA_URL</span></code></a>.</li>
</ul>
<div class="section" id="s-static-file-development-view">
<span id="s-staticfiles-development-view"></span><span id="static-file-development-view"></span><span id="staticfiles-development-view"></span><h3>Static file development view<a class="headerlink" href="#static-file-development-view" title="Permalink to this headline">¶</a></h3>
<p>The static files tools are mostly designed to help with getting static files
successfully deployed into production. This usually means a separate,
dedicated static file server, which is a lot of overhead to mess with when
developing locally. Thus, the <code class="docutils literal"><span class="pre">staticfiles</span></code> app ships with a
<strong>quick and dirty helper view</strong> that you can use to serve files locally in
development.</p>
<dl class="function">
<dt id="django.contrib.staticfiles.views.serve">
<code class="descclassname">views.</code><code class="descname">serve</code>(<em>request</em>, <em>path</em>)<a class="headerlink" href="#django.contrib.staticfiles.views.serve" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>This view function serves static files in development.</p>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p>This view will only work if <a class="reference internal" href="../settings.html#std:setting-DEBUG"><code class="xref std std-setting docutils literal"><span class="pre">DEBUG</span></code></a> is <code class="docutils literal"><span class="pre">True</span></code>.</p>
<p class="last">That&#8217;s because this view is <strong>grossly inefficient</strong> and probably
<strong>insecure</strong>. This is only intended for local development, and should
<strong>never be used in production</strong>.</p>
</div>
<div class="versionchanged">
<span class="title">Changed in Django 1.7:</span> <p>This view will now raise an <a class="reference internal" href="../../topics/http/views.html#django.http.Http404" title="django.http.Http404"><code class="xref py py-exc docutils literal"><span class="pre">Http404</span></code></a> exception instead
of <a class="reference internal" href="../exceptions.html#django.core.exceptions.ImproperlyConfigured" title="django.core.exceptions.ImproperlyConfigured"><code class="xref py py-exc docutils literal"><span class="pre">ImproperlyConfigured</span></code></a> when
<a class="reference internal" href="../settings.html#std:setting-DEBUG"><code class="xref std std-setting docutils literal"><span class="pre">DEBUG</span></code></a> is <code class="docutils literal"><span class="pre">False</span></code>.</p>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">To guess the served files&#8217; content types, this view relies on the
<code class="xref py py-mod docutils literal"><span class="pre">mimetypes</span></code> module from the Python standard library, which itself
relies on the underlying platform&#8217;s map files. If you find that this view
doesn&#8217;t return proper content types for certain files, it is most likely
that the platform&#8217;s map files need to be updated. This can be achieved, for
example, by installing or updating the <code class="docutils literal"><span class="pre">mailcap</span></code> package on a Red Hat
distribution, or <code class="docutils literal"><span class="pre">mime-support</span></code> on a Debian distribution.</p>
</div>
<p>This view is automatically enabled by <a class="reference internal" href="../django-admin.html#django-admin-runserver"><code class="xref std std-djadmin docutils literal"><span class="pre">runserver</span></code></a> (with a
<a class="reference internal" href="../settings.html#std:setting-DEBUG"><code class="xref std std-setting docutils literal"><span class="pre">DEBUG</span></code></a> setting set to <code class="docutils literal"><span class="pre">True</span></code>). To use the view with a different
local development server, add the following snippet to the end of your
primary URL configuration:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">django.conf</span> <span class="kn">import</span> <span class="n">settings</span>
<span class="kn">from</span> <span class="nn">django.contrib.staticfiles</span> <span class="kn">import</span> <span class="n">views</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="n">urlpatterns</span> <span class="o">+=</span> <span class="p">[</span>
        <span class="n">url</span><span class="p">(</span><span class="s1">r&#39;^static/(?P&lt;path&gt;.*)$&#39;</span><span class="p">,</span> <span class="n">views</span><span class="o">.</span><span class="n">serve</span><span class="p">),</span>
    <span class="p">]</span>
</pre></div>
</div>
<p>Note, the beginning of the pattern (<code class="docutils literal"><span class="pre">r'^static/'</span></code>) should be your
<a class="reference internal" href="../settings.html#std:setting-STATIC_URL"><code class="xref std std-setting docutils literal"><span class="pre">STATIC_URL</span></code></a> setting.</p>
<p>Since this is a bit finicky, there&#8217;s also a helper function that&#8217;ll do this for
you:</p>
<dl class="function">
<dt id="django.contrib.staticfiles.urls.staticfiles_urlpatterns">
<code class="descclassname">urls.</code><code class="descname">staticfiles_urlpatterns</code>()<a class="headerlink" href="#django.contrib.staticfiles.urls.staticfiles_urlpatterns" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>This will return the proper URL pattern for serving static files to your
already defined pattern list. Use it like this:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">django.contrib.staticfiles.urls</span> <span class="kn">import</span> <span class="n">staticfiles_urlpatterns</span>

<span class="c1"># ... the rest of your URLconf here ...</span>

<span class="n">urlpatterns</span> <span class="o">+=</span> <span class="n">staticfiles_urlpatterns</span><span class="p">()</span>
</pre></div>
</div>
<p>This will inspect your <a class="reference internal" href="../settings.html#std:setting-STATIC_URL"><code class="xref std std-setting docutils literal"><span class="pre">STATIC_URL</span></code></a> setting and wire up the view
to serve static files accordingly. Don&#8217;t forget to set the
<a class="reference internal" href="../settings.html#std:setting-STATICFILES_DIRS"><code class="xref std std-setting docutils literal"><span class="pre">STATICFILES_DIRS</span></code></a> setting appropriately to let
<code class="docutils literal"><span class="pre">django.contrib.staticfiles</span></code> know where to look for files in addition to
files in app directories.</p>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p>This helper function will only work if <a class="reference internal" href="../settings.html#std:setting-DEBUG"><code class="xref std std-setting docutils literal"><span class="pre">DEBUG</span></code></a> is <code class="docutils literal"><span class="pre">True</span></code>
and your <a class="reference internal" href="../settings.html#std:setting-STATIC_URL"><code class="xref std std-setting docutils literal"><span class="pre">STATIC_URL</span></code></a> setting is neither empty nor a full
URL such as <code class="docutils literal"><span class="pre">http://static.example.com/</span></code>.</p>
<p class="last">That&#8217;s because this view is <strong>grossly inefficient</strong> and probably
<strong>insecure</strong>. This is only intended for local development, and should
<strong>never be used in production</strong>.</p>
</div>
</div>
<div class="section" id="s-specialized-test-case-to-support-live-testing">
<span id="specialized-test-case-to-support-live-testing"></span><h3>Specialized test case to support &#8216;live testing&#8217;<a class="headerlink" href="#specialized-test-case-to-support-live-testing" title="Permalink to this headline">¶</a></h3>
<dl class="class">
<dt id="django.contrib.staticfiles.testing.StaticLiveServerTestCase">
<em class="property">class </em><code class="descclassname">testing.</code><code class="descname">StaticLiveServerTestCase</code><a class="headerlink" href="#django.contrib.staticfiles.testing.StaticLiveServerTestCase" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>This unittest TestCase subclass extends <a class="reference internal" href="../../topics/testing/tools.html#django.test.LiveServerTestCase" title="django.test.LiveServerTestCase"><code class="xref py py-class docutils literal"><span class="pre">django.test.LiveServerTestCase</span></code></a>.</p>
<p>Just like its parent, you can use it to write tests that involve running the
code under test and consuming it with testing tools through HTTP (e.g. Selenium,
PhantomJS, etc.), because of which it&#8217;s needed that the static assets are also
published.</p>
<p>But given the fact that it makes use of the
<a class="reference internal" href="#django.contrib.staticfiles.views.serve" title="django.contrib.staticfiles.views.serve"><code class="xref py py-func docutils literal"><span class="pre">django.contrib.staticfiles.views.serve()</span></code></a> view described above, it can
transparently overlay at test execution-time the assets provided by the
<code class="docutils literal"><span class="pre">staticfiles</span></code> finders. This means you don&#8217;t need to run
<a class="reference internal" href="#django-admin-collectstatic"><code class="xref std std-djadmin docutils literal"><span class="pre">collectstatic</span></code></a> before or as a part of your tests setup.</p>
<div class="versionadded">
<span class="title">New in Django 1.7:</span> <p><code class="docutils literal"><span class="pre">StaticLiveServerTestCase</span></code> is new in Django 1.7. Previously its
functionality was provided by <a class="reference internal" href="../../topics/testing/tools.html#django.test.LiveServerTestCase" title="django.test.LiveServerTestCase"><code class="xref py py-class docutils literal"><span class="pre">django.test.LiveServerTestCase</span></code></a>.</p>
</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="#">The staticfiles app</a><ul>
<li><a class="reference internal" href="#settings">Settings</a></li>
<li><a class="reference internal" href="#management-commands">Management Commands</a><ul>
<li><a class="reference internal" href="#collectstatic">collectstatic</a></li>
<li><a class="reference internal" href="#findstatic">findstatic</a></li>
<li><a class="reference internal" href="#runserver">runserver</a></li>
</ul>
</li>
<li><a class="reference internal" href="#storages">Storages</a><ul>
<li><a class="reference internal" href="#staticfilesstorage">StaticFilesStorage</a></li>
<li><a class="reference internal" href="#manifeststaticfilesstorage">ManifestStaticFilesStorage</a></li>
<li><a class="reference internal" href="#cachedstaticfilesstorage">CachedStaticFilesStorage</a></li>
</ul>
</li>
<li><a class="reference internal" href="#template-tags">Template tags</a><ul>
<li><a class="reference internal" href="#static">static</a></li>
</ul>
</li>
<li><a class="reference internal" href="#finders-module">Finders Module</a></li>
<li><a class="reference internal" href="#other-helpers">Other Helpers</a><ul>
<li><a class="reference internal" href="#static-file-development-view">Static file development view</a></li>
<li><a class="reference internal" href="#specialized-test-case-to-support-live-testing">Specialized test case to support &#8216;live testing&#8217;</a></li>
</ul>
</li>
</ul>
</li>
</ul>

  <h3>Browse</h3>
  <ul>
    
      <li>Prev: <a href="sites.html">The &#8220;sites&#8221; framework</a></li>
    
    
      <li>Next: <a href="syndication.html">The syndication feed framework</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">API Reference</a>
        
          <ul><li><a href="index.html"><code class="docutils literal"><span class="pre">contrib</span></code> packages</a>
        
        <ul><li>The staticfiles app</li></ul>
        </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/ref/contrib/staticfiles.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="sites.html" title="The &amp;#8220;sites&amp;#8221; framework">previous</a>
     |
    <a href="../index.html" title="API Reference" accesskey="U">up</a>
   |
    <a href="syndication.html" title="The syndication feed framework">next</a> &raquo;</div>
    </div>
  </div>

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