Skip to content

Commit dc5c8f5

Browse files
committed
working on wsgi server pages
1 parent 8e8cc54 commit dc5c8f5

File tree

88 files changed

+514
-75
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+514
-75
lines changed

about-author.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

all.html

Lines changed: 86 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1985,8 +1985,8 @@ <h2>Django learning checklist</h2>
19851985
</ol>
19861986
<h1>Flask</h1>
19871987
<p><a href="http://flask.pocoo.org/">Flask</a> is a Python web framework built with a
1988-
<a href="http://flask.pocoo.org/docs/design/">small core and easy-to-extend philosophy</a>.
1989-
<a href="http://flask.pocoo.org/" style="border: none;"><img src="/img/flask.jpg" width="100%" alt="Official Flask logo. Flask Artwork License." class="technical-diagram"></a></p>
1988+
<a href="http://flask.pocoo.org/docs/design/">small core and easy-to-extend philosophy</a>. </p>
1989+
<p><a href="http://flask.pocoo.org/" style="border: none;"><img src="/img/flask.jpg" width="100%" alt="Official Flask logo. Flask Artwork License." class="technical-diagram"></a></p>
19901990
<h2>Why is Flask a good web framework choice?</h2>
19911991
<p>Flask is considered more
19921992
<a href="http://blog.startifact.com/posts/older/what-is-pythonic.html">Pythonic</a>
@@ -8207,6 +8207,90 @@ <h3>General Caddy resources</h3>
82078207
use. Sponsors and optional donations are currently used to fund ongoing
82088208
development.</p>
82098209
</li>
8210+
</ul>
8211+
<h1>Green Unicorn (Gunicorn)</h1>
8212+
<p><a href="http://gunicorn.org/">Green Unicorn</a>, commonly shortened to "Gunicorn",
8213+
is a <a href="/wsgi-servers.html">Web Server Gateway Interface (WSGI) server</a>
8214+
implementation that is commonly used to run Python web applications.</p>
8215+
<p><a href="http://gunicorn.org/" style="border: none;"><img src="/img/gunicorn-logo.jpg" width="100%" alt="Official Green Unicorn (Gunicorn) logo." class="technical-diagram"></a></p>
8216+
<h2>Why is Gunicorn important?</h2>
8217+
<p>Gunicorn is one of many WSGI server implementations, but it's particularly
8218+
important because it is a stable, commonly-used part of
8219+
<a href="/deployments.html">web app deployments</a> that's powered some of the
8220+
largest Python-powered web applications in the world, such as
8221+
<a href="http://instagram-engineering.tumblr.com/post/13649370142/what-powers-instagram-hundreds-of-instances">Instagram</a>.</p>
8222+
<p>Gunicorn implements the
8223+
<a href="https://www.python.org/dev/peps/pep-3333/">PEP3333 WSGI server standard specification</a>
8224+
so that it can run Python web applications that implement the application
8225+
interface. For example, if you write a web application with a
8226+
<a href="/web-frameworks.html">web framework</a> such as <a href="/django.html">Django</a>,
8227+
<a href="/flask.html">Flask</a> or <a href="/bottle.html">Bottle</a>, then your application
8228+
implements the WSGI specification. </p>
8229+
<h2>How does Gunicorn know how to run my web app?</h2>
8230+
<p>Gunicorn knows how to run a web application based on the hook between the
8231+
WSGI server and the WSGI-compliant web app.</p>
8232+
<p>Here is an example of a typical Django web application and how it is run
8233+
by Gunicorn. We'll use the
8234+
<a href="https://github.com/makaimc/compare-python-web-frameworks/tree/master/django_defaults">django_defaults</a>
8235+
as an example Django project. Within the <a href="https://github.com/makaimc/compare-python-web-frameworks/tree/master/django_defaults/django_defaults">django_defaults</a>
8236+
project subdirectory, there is a short <a href="https://github.com/makaimc/compare-python-web-frameworks/blob/master/django_defaults/django_defaults/wsgi.py">wsgi.py</a>
8237+
file with the following contents:</p>
8238+
<div class="highlight"><pre><span class="sd">&quot;&quot;&quot;</span>
8239+
<span class="sd">WSGI config for django_defaults project.</span>
8240+
8241+
<span class="sd">It exposes the WSGI callable as a module-level variable named ``application``.</span>
8242+
8243+
<span class="sd">For more information on this file, see</span>
8244+
<span class="sd">https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/</span>
8245+
<span class="sd">&quot;&quot;&quot;</span>
8246+
8247+
<span class="kn">import</span> <span class="nn">os</span>
8248+
8249+
<span class="kn">from</span> <span class="nn">django.core.wsgi</span> <span class="kn">import</span> <span class="n">get_wsgi_application</span>
8250+
8251+
<span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="o">.</span><span class="n">setdefault</span><span class="p">(</span><span class="s">&quot;DJANGO_SETTINGS_MODULE&quot;</span><span class="p">,</span> <span class="s">&quot;django_defaults.settings&quot;</span><span class="p">)</span>
8252+
8253+
<span class="n">application</span> <span class="o">=</span> <span class="n">get_wsgi_application</span><span class="p">()</span>
8254+
</pre></div>
8255+
8256+
8257+
<p>That <code>wsgi.py</code> file was generated by the <code>django-admin.py startproject</code> command
8258+
when the Django project was first created. Django exposes an <code>application</code>
8259+
variable via that <code>wsgi.py</code> file so that a WSGI server can use <code>application</code>
8260+
as a hook for running the web app. Here's how the situation looks visually:</p>
8261+
<p><img src="/img/gunicorn-django-wsgi.png" alt="Gunicorn WSGI server invoking a Django WSGI application." width="100%" class="technical-diagram" /></p>
8262+
<h2>What's a "pre-fork" worker model?</h2>
8263+
<p>Gunicorn is based on a pre-fork worker model, compared to a worker model
8264+
architecture. The pre-work worker model means that a master thread spins up
8265+
workers to handle requests but otherwise does not control how those workers
8266+
perform the request handling. Each worker is independent of the controller.</p>
8267+
<h3>Gunicorn resources</h3>
8268+
<ul>
8269+
<li>
8270+
<p><a href="http://adambeagle.com/blog/deploying-django-17-ubuntu/">Deploying Django 1.7 on Ubuntu with DigitalOcean with PostgreSQL, Nginx, and Gunicorn</a>
8271+
is a detailed walkthrough that uses Green Unicorn as the WSGI server part of
8272+
the deployment.</p>
8273+
</li>
8274+
<li>
8275+
<p>The <a href="http://www.deploypython.com/">Full Stack Python Guide to Deployments</a>
8276+
provides detailed step-by-step instructions for deploying Gunicorn as part
8277+
of an entire Python web application deployment.</p>
8278+
</li>
8279+
<li>
8280+
<p><a href="http://prakhar.me/articles/flask-on-nginx-and-gunicorn/">Flask on Nginx and Gunicorn</a>
8281+
combines the <a href="/nginx.html">Nginx web server</a> with Gunicorn in a deployment
8282+
to serve up a Flask application.</p>
8283+
</li>
8284+
<li>
8285+
<p>The answers to the question "<a href="http://stackoverflow.com/questions/16857955/running-django-with-gunicorn-best-practice">what's the best practice for running Django with Gunicorn?</a>"
8286+
provide some nuance for how Gunicorn should be invokin the callable application
8287+
variable provided by Django within a deployment.</p>
8288+
</li>
8289+
<li>
8290+
<p><a href="http://linoxide.com/linux-how-to/install-django-gunicorn-nginx-freebsd-10-2/">How to Install Django with Gunicorn and Nginx on FreeBSD 10.2</a>
8291+
is a tutorial for FreeBSD, which is not often used in walkthroughs compared to
8292+
the frequency that Ubuntu and CentOS tutorials appear.</p>
8293+
</li>
82108294
</ul>
82118295
<h1>Testing</h1>
82128296
<p>Testing determines whether software runs correctly based on specific inputs

apache-http-server.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

api-creation.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

api-integration.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

application-dependencies.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

application-programming-interfaces.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

best-python-resources.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

best-python-videos.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

bots.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)