Sophie

Sophie

distrib > Fedora > 20 > i386 > by-pkgid > 422242acff54b9373d7d4b7f73232ce1 > files > 508

python3-django-doc-1.6.7-1.fc20.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">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>How to use Django with uWSGI &mdash; Django 1.6.7 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.6.7',
        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="top" title="Django 1.6.7 documentation" href="../../../index.html" />
    <link rel="up" title="How to deploy with WSGI" href="index.html" />
    <link rel="next" title="How to use Django with FastCGI, SCGI, or AJP" href="../fastcgi.html" />
    <link rel="prev" title="How to use Django with Gunicorn" href="gunicorn.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>

    <div class="document">
  <div id="custom-doc" class="yui-t6">
    <div id="hd">
      <h1><a href="../../../index.html">Django 1.6.7 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="gunicorn.html" title="How to use Django with Gunicorn">previous</a> 
     |
    <a href="../../index.html" title="&amp;#8220;How-to&amp;#8221; guides" accesskey="U">up</a>
   |
    <a href="../fastcgi.html" title="How to use Django with FastCGI, SCGI, or AJP">next</a> &raquo;</div>
    </div>
    
    <div id="bd">
      <div id="yui-main">
        <div class="yui-b">
          <div class="yui-g" id="howto-deployment-wsgi-uwsgi">
            
  <div class="section" id="s-how-to-use-django-with-uwsgi">
<span id="how-to-use-django-with-uwsgi"></span><h1>How to use Django with uWSGI<a class="headerlink" href="#how-to-use-django-with-uwsgi" title="Permalink to this headline">¶</a></h1>
<p><a class="reference external" href="http://projects.unbit.it/uwsgi/">uWSGI</a> is a fast, self-healing and developer/sysadmin-friendly application
container server coded in pure C.</p>
<div class="admonition-see-also admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last">The uWSGI docs offer a <a class="reference external" href="https://uwsgi.readthedocs.org/en/latest/tutorials/Django_and_nginx.html">tutorial</a> covering Django, nginx, and uWSGI (one
possible deployment setup of many). The docs below are focused on how to
integrate Django with uWSGI.</p>
</div>
<div class="section" id="s-prerequisite-uwsgi">
<span id="prerequisite-uwsgi"></span><h2>Prerequisite: uWSGI<a class="headerlink" href="#prerequisite-uwsgi" title="Permalink to this headline">¶</a></h2>
<p>The uWSGI wiki describes several <a class="reference external" href="http://uwsgi-docs.readthedocs.org/en/latest/Install.html">installation procedures</a>. Using pip, the
Python package manager, you can install any uWSGI version with a single
command. For example:</p>
<div class="highlight-bash"><div class="highlight"><pre><span class="c"># Install current stable version.</span>
<span class="nv">$ </span>sudo pip install uwsgi

<span class="c"># Or install LTS (long term support).</span>
<span class="nv">$ </span>sudo pip install http://projects.unbit.it/downloads/uwsgi-lts.tar.gz
</pre></div>
</div>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last">Some distributions, including Debian and Ubuntu, ship an outdated version
of uWSGI that does not conform to the WSGI specification. Versions prior to
1.2.6 do not call <tt class="docutils literal"><span class="pre">close</span></tt> on the response object after handling a
request. In those cases the <a class="reference internal" href="../../../ref/signals.html#django.core.signals.request_finished" title="django.core.signals.request_finished"><tt class="xref py py-data docutils literal"><span class="pre">request_finished</span></tt></a>
signal isn&#8217;t sent. This can result in idle connections to database and
memcache servers.</p>
</div>
<div class="section" id="s-uwsgi-model">
<span id="uwsgi-model"></span><h3>uWSGI model<a class="headerlink" href="#uwsgi-model" title="Permalink to this headline">¶</a></h3>
<p>uWSGI operates on a client-server model. Your Web server (e.g., nginx, Apache)
communicates with a django-uwsgi &#8220;worker&#8221; process to serve dynamic content.
See uWSGI&#8217;s <a class="reference external" href="http://projects.unbit.it/uwsgi/wiki/Background">background documentation</a> for more detail.</p>
</div>
<div class="section" id="s-configuring-and-starting-the-uwsgi-server-for-django">
<span id="configuring-and-starting-the-uwsgi-server-for-django"></span><h3>Configuring and starting the uWSGI server for Django<a class="headerlink" href="#configuring-and-starting-the-uwsgi-server-for-django" title="Permalink to this headline">¶</a></h3>
<p>uWSGI supports multiple ways to configure the process. See uWSGI&#8217;s
<a class="reference external" href="https://uwsgi.readthedocs.org/en/latest/Configuration.html">configuration documentation</a> and <a class="reference external" href="http://projects.unbit.it/uwsgi/wiki/Example">examples</a></p>
<p>Here&#8217;s an example command to start a uWSGI server:</p>
<div class="highlight-bash"><div class="highlight"><pre>uwsgi --chdir<span class="o">=</span>/path/to/your/project <span class="se">\</span>
    --module<span class="o">=</span>mysite.wsgi:application <span class="se">\</span>
    --env <span class="nv">DJANGO_SETTINGS_MODULE</span><span class="o">=</span>mysite.settings <span class="se">\</span>
    --master --pidfile<span class="o">=</span>/tmp/project-master.pid <span class="se">\</span>
    --socket<span class="o">=</span>127.0.0.1:49152 <span class="se">\ </span>     <span class="c"># can also be a file</span>
    --processes<span class="o">=</span>5 <span class="se">\ </span>                <span class="c"># number of worker processes</span>
    --uid<span class="o">=</span>1000 --gid<span class="o">=</span>2000 <span class="se">\ </span>        <span class="c"># if root, uwsgi can drop privileges</span>
    --harakiri<span class="o">=</span>20 <span class="se">\ </span>                <span class="c"># respawn processes taking more than 20 seconds</span>
    --max-requests<span class="o">=</span>5000 <span class="se">\ </span>          <span class="c"># respawn processes after serving 5000 requests</span>
    --vacuum <span class="se">\ </span>                     <span class="c"># clear environment on exit</span>
    --home<span class="o">=</span>/path/to/virtual/env <span class="se">\ </span>  <span class="c"># optional path to a virtualenv</span>
    --daemonize<span class="o">=</span>/var/log/uwsgi/yourproject.log      <span class="c"># background the process</span>
</pre></div>
</div>
<p>This assumes you have a top-level project package named <tt class="docutils literal"><span class="pre">mysite</span></tt>, and
within it a module <tt class="file docutils literal"><span class="pre">mysite/wsgi.py</span></tt> that contains a WSGI <tt class="docutils literal"><span class="pre">application</span></tt>
object. This is the layout you&#8217;ll have if you ran <tt class="docutils literal"><span class="pre">django-admin.py</span>
<span class="pre">startproject</span> <span class="pre">mysite</span></tt> (using your own project name in place of <tt class="docutils literal"><span class="pre">mysite</span></tt>) with
a recent version of Django. If this file doesn&#8217;t exist, you&#8217;ll need to create
it. See the <a class="reference internal" href="index.html"><em>How to deploy with WSGI</em></a> documentation for the default
contents you should put in this file and what else you can add to it.</p>
<p>The Django-specific options here are:</p>
<ul class="simple">
<li><tt class="docutils literal"><span class="pre">chdir</span></tt>: The path to the directory that needs to be on Python&#8217;s import
path &#8211; i.e., the directory containing the <tt class="docutils literal"><span class="pre">mysite</span></tt> package.</li>
<li><tt class="docutils literal"><span class="pre">module</span></tt>: The WSGI module to use &#8211; probably the <tt class="docutils literal"><span class="pre">mysite.wsgi</span></tt> module
that <a class="reference internal" href="../../../ref/django-admin.html#django-admin-startproject"><tt class="xref std std-djadmin docutils literal"><span class="pre">startproject</span></tt></a> creates.</li>
<li><tt class="docutils literal"><span class="pre">env</span></tt>: Should probably contain at least <tt class="docutils literal"><span class="pre">DJANGO_SETTINGS_MODULE</span></tt>.</li>
<li><tt class="docutils literal"><span class="pre">home</span></tt>: Optional path to your project virtualenv.</li>
</ul>
<p>Example ini configuration file:</p>
<div class="highlight-bash"><div class="highlight"><pre><span class="o">[</span>uwsgi<span class="o">]</span>
<span class="nv">chdir</span><span class="o">=</span>/path/to/your/project
<span class="nv">module</span><span class="o">=</span>mysite.wsgi:application
<span class="nv">master</span><span class="o">=</span>True
<span class="nv">pidfile</span><span class="o">=</span>/tmp/project-master.pid
<span class="nv">vacuum</span><span class="o">=</span>True
max-requests<span class="o">=</span>5000
<span class="nv">daemonize</span><span class="o">=</span>/var/log/uwsgi/yourproject.log
</pre></div>
</div>
<p>Example ini configuration file usage:</p>
<div class="highlight-bash"><div class="highlight"><pre>uwsgi --ini uwsgi.ini
</pre></div>
</div>
<p>See the uWSGI docs on <a class="reference external" href="http://uwsgi-docs.readthedocs.org/en/latest/Management.html">managing the uWSGI process</a> for information on
starting, stopping and reloading the uWSGI workers.</p>
</div>
</div>
</div>


          </div>         
        </div>
      </div>
      
        
          <div class="yui-b" id="sidebar">
            
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../../../contents.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">How to use Django with uWSGI</a><ul>
<li><a class="reference internal" href="#prerequisite-uwsgi">Prerequisite: uWSGI</a><ul>
<li><a class="reference internal" href="#uwsgi-model">uWSGI model</a></li>
<li><a class="reference internal" href="#configuring-and-starting-the-uwsgi-server-for-django">Configuring and starting the uWSGI server for Django</a></li>
</ul>
</li>
</ul>
</li>
</ul>

  <h3>Browse</h3>
  <ul>
    
      <li>Prev: <a href="gunicorn.html">How to use Django with Gunicorn</a></li>
    
    
      <li>Next: <a href="../fastcgi.html">How to use Django with FastCGI, SCGI, or AJP</a></li>
    
  </ul>
  <h3>You are here:</h3>
  <ul>
      <li>
        <a href="../../../index.html">Django 1.6.7 documentation</a>
        
          <ul><li><a href="../../index.html">&#8220;How-to&#8221; guides</a>
        
          <ul><li><a href="../index.html">Deploying Django</a>
        
          <ul><li><a href="index.html">How to deploy with WSGI</a>
        
        <ul><li>How to use Django with uWSGI</li></ul>
        </li></ul></li></ul></li></ul>
      </li>
  </ul>  

  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="../../../_sources/howto/deployment/wsgi/uwsgi.txt"
           rel="nofollow">Show Source</a></li>
  </ul>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
              <h3>Last update:</h3>
              <p class="topless">Sep 26, 2014</p>
          </div> 
        
      
    </div>
    
    <div id="ft">
      <div class="nav">
    &laquo; <a href="gunicorn.html" title="How to use Django with Gunicorn">previous</a> 
     |
    <a href="../../index.html" title="&amp;#8220;How-to&amp;#8221; guides" accesskey="U">up</a>
   |
    <a href="../fastcgi.html" title="How to use Django with FastCGI, SCGI, or AJP">next</a> &raquo;</div>
    </div>
  </div>

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