mirror of
https://github.com/kennethreitz-archive/conductofcode.git
synced 2026-06-05 23:30:19 +00:00
355 lines
19 KiB
HTML
355 lines
19 KiB
HTML
|
|
<!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>Web Applications — pythonguide 0.0.1 documentation</title>
|
|
|
|
<link rel="stylesheet" href="../_static/flasky.css" type="text/css" />
|
|
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
|
|
|
<script type="text/javascript">
|
|
var DOCUMENTATION_OPTIONS = {
|
|
URL_ROOT: '../',
|
|
VERSION: '0.0.1',
|
|
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="pythonguide 0.0.1 documentation" href="../index.html" />
|
|
<link rel="next" title="Command Line Applications" href="cli.html" />
|
|
<link rel="prev" title="Choosing a License" href="../writing/license.html" />
|
|
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9">
|
|
|
|
</head>
|
|
<body>
|
|
<div class="related">
|
|
<h3>Navigation</h3>
|
|
<ul>
|
|
<li class="right" style="margin-right: 10px">
|
|
<a href="../genindex.html" title="General Index"
|
|
accesskey="I">index</a></li>
|
|
<li class="right" >
|
|
<a href="cli.html" title="Command Line Applications"
|
|
accesskey="N">next</a> |</li>
|
|
<li class="right" >
|
|
<a href="../writing/license.html" title="Choosing a License"
|
|
accesskey="P">previous</a> |</li>
|
|
<li><a href="../index.html">pythonguide 0.0.1 documentation</a> »</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<div class="document">
|
|
<div class="documentwrapper">
|
|
<div class="bodywrapper">
|
|
<div class="body">
|
|
|
|
<div class="section" id="web-applications">
|
|
<h1>Web Applications<a class="headerlink" href="#web-applications" title="Permalink to this headline">¶</a></h1>
|
|
<div class="section" id="context">
|
|
<h2>Context<a class="headerlink" href="#context" title="Permalink to this headline">¶</a></h2>
|
|
<div class="section" id="wsgi">
|
|
<h3>WSGI<a class="headerlink" href="#wsgi" title="Permalink to this headline">¶</a></h3>
|
|
<p>The Web Server Gateway Interface (or “WSGI” for short) is a standard
|
|
interface between web servers and Python web application frameworks. By
|
|
standardizing behavior and communication between web servers and Python web
|
|
frameworks, WSGI makes it possible to write portable Python web code that
|
|
can be deployed in any <a class="reference internal" href="#wsgi-servers-ref"><em>WSGI-compliant web server</em></a>. WSGI is
|
|
documented in <a class="reference external" href="http://www.python.org/dev/peps/pep-3333/">PEP-3333</a>.</p>
|
|
</div>
|
|
</div>
|
|
<div class="section" id="frameworks">
|
|
<h2>Frameworks<a class="headerlink" href="#frameworks" title="Permalink to this headline">¶</a></h2>
|
|
<p>Broadly speaking, a web framework is a set of libraries upon which you can
|
|
build custom code to implement a web application (i.e. an interactive web
|
|
site). Most web frameworks include patterns and utilities to accomplish at
|
|
least the following:</p>
|
|
<dl class="docutils">
|
|
<dt>URL Routing</dt>
|
|
<dd>Matches an incoming HTTP request to a particular piece of Python code to
|
|
be invoked</dd>
|
|
<dt>Request and Response Objects</dt>
|
|
<dd>Encapsulate the information received from or sent to a user’s browser</dd>
|
|
<dt>Template Engine</dt>
|
|
<dd>Allows for separating Python code implementing an application’s logic from
|
|
the HTML (or other) output that it produces</dd>
|
|
<dt>Development Web Server</dt>
|
|
<dd>Runs an HTTP server on development machines to enable rapid development;
|
|
often automatically reloads server-side code when files are updated</dd>
|
|
</dl>
|
|
<div class="section" id="django">
|
|
<h3>Django<a class="headerlink" href="#django" title="Permalink to this headline">¶</a></h3>
|
|
<p><a class="reference external" href="http://www.djangoproject.com">Django</a> is a “batteries included” web
|
|
application framework. By providing many utilities and patterns out of the
|
|
box, Django aims to make it possible to build complex, database-backed web
|
|
applications quickly, while encouraging best practices in code written using
|
|
it.</p>
|
|
<p>Django has a large and active community, and many pre-built <a class="reference external" href="http://djangopackages.com/">re-usable
|
|
modules</a> that can be incorporated into a new
|
|
project as-is, or customized to fit your needs.</p>
|
|
<p>There are annual Django conferences <a class="reference external" href="http://djangocon.us">in the United States</a> and <a class="reference external" href="http://djangocon.eu">in Europe</a>.</p>
|
|
</div>
|
|
<div class="section" id="flask">
|
|
<h3>Flask<a class="headerlink" href="#flask" title="Permalink to this headline">¶</a></h3>
|
|
<p><a class="reference external" href="http://flask.pocoo.org/">Flask</a> is a “microframework” for Python. Rather
|
|
than aiming to provide everything you could possibly need, Flask implements
|
|
the most commonly-used core components of a web application framework, like
|
|
URL routing, request and response objects, and templates. As a user of
|
|
Flask, it is therefore up to you to choose and integrate other components
|
|
you may need, such as database access or form generation and validation. For
|
|
many popular modules, <a class="reference external" href="http://flask.pocoo.org/extensions/">Extensions</a> may
|
|
already exist to suit your needs.</p>
|
|
<p><strong>Support</strong> for flask can best be found in its mailing list. Just shoot an email to
|
|
<a class="reference external" href="mailto:flask%40librelist.com">flask<span>@</span>librelist<span>.</span>com</a> and reply to the confirmation email.</p>
|
|
<div class="admonition-todo admonition" id="index-0">
|
|
<p class="first admonition-title">Todo</p>
|
|
<p class="last">Explain Pyramid</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="section" id="web-servers">
|
|
<h2>Web Servers<a class="headerlink" href="#web-servers" title="Permalink to this headline">¶</a></h2>
|
|
<div class="section" id="nginx">
|
|
<span id="nginx-ref"></span><h3>Nginx<a class="headerlink" href="#nginx" title="Permalink to this headline">¶</a></h3>
|
|
<p><a class="reference external" href="http://nginx.org/">Nginx</a> (pronounced “engine-x”) is a web server and
|
|
reverse-proxy for HTTP, SMTP and other protocols. It is known for its
|
|
high performance, relative simplicity, and compatibility with many
|
|
application servers (like WSGI servers). It also includes handy features
|
|
like load-balancing, basic authentication, streaming, and others. Designed
|
|
to serve high-load websites, Nginx is gradually becoming quite popular.</p>
|
|
</div>
|
|
</div>
|
|
<div class="section" id="wsgi-servers">
|
|
<span id="wsgi-servers-ref"></span><h2>WSGI Servers<a class="headerlink" href="#wsgi-servers" title="Permalink to this headline">¶</a></h2>
|
|
<p>Stand-alone WSGI servers typically use less resources than traditional web
|
|
servers and provide top performance <a class="footnote-reference" href="#id13" id="id4">[3]</a>.</p>
|
|
<div class="section" id="gunicorn">
|
|
<span id="gunicorn-ref"></span><h3>Gunicorn<a class="headerlink" href="#gunicorn" title="Permalink to this headline">¶</a></h3>
|
|
<p><a class="reference external" href="http://gunicorn.org/">Gunicorn</a> (Green Unicorn) is a WSGI server used
|
|
to serve Python applications. It is a Python interpretation of the Ruby
|
|
<a class="reference external" href="http://unicorn.bogomips.org/">Unicorn</a> server. Unicorn is designed to be
|
|
lightweight, easy to use, and uses many UNIX idioms. Gunicorn is not designed
|
|
to face the internet, in fact it was designed to run behind Nginx which buffers
|
|
slow requests, and takes care of other important considerations. A sample
|
|
setup for Nginx + gUnicorn can be found in the
|
|
<a class="reference external" href="http://gunicorn.org/deploy.html">Gunicorn help</a>.</p>
|
|
</div>
|
|
</div>
|
|
<div class="section" id="server-best-practices">
|
|
<span id="uwsgi-ref"></span><h2>Server Best Practices<a class="headerlink" href="#server-best-practices" title="Permalink to this headline">¶</a></h2>
|
|
<p>The majority of self hosted Python applications today are hosted with a WSGI
|
|
server such as <a class="reference internal" href="#gunicorn-ref"><em>gUnicorn</em></a>, either directly or behind a
|
|
lightweight web server such as <a class="reference internal" href="#nginx-ref"><em>nginx</em></a>.</p>
|
|
<p>The WSGI servers serve the Python applications while the web server handles tasks
|
|
better suited for it such as static file serving, request routing, DDoS
|
|
protection, and basic authentication.</p>
|
|
</div>
|
|
<div class="section" id="hosting">
|
|
<h2>Hosting<a class="headerlink" href="#hosting" title="Permalink to this headline">¶</a></h2>
|
|
<div class="section" id="platform-as-a-service">
|
|
<h3>Platform-as-a-Service<a class="headerlink" href="#platform-as-a-service" title="Permalink to this headline">¶</a></h3>
|
|
<p>Platform-as-a-Service (PaaS) is a type of cloud computing infrastructure
|
|
which abstracts and manages infrastructure, routing, and scaling of web
|
|
applications. When using PaaS, application developers can focus on writing
|
|
application code rather than needing to be concerned with deployment
|
|
details.</p>
|
|
<p>Most PaaS services offer a command-line interface that developers can use to
|
|
set up and interrogate configuration, and to deploy new releases of an
|
|
application to the service.</p>
|
|
<p>PaaS services and their partners offer add-on functionality which is well
|
|
integrated into the platform, such as database hosting, email services,
|
|
logging, scheduled and background tasks, billing and payment, etc.</p>
|
|
<div class="section" id="heroku">
|
|
<h4>Heroku<a class="headerlink" href="#heroku" title="Permalink to this headline">¶</a></h4>
|
|
<p><a class="reference external" href="http://www.heroku.com/">Heroku</a>‘s
|
|
<a class="reference external" href="http://devcenter.heroku.com/articles/cedar">Cedar stack</a> offers first class
|
|
support for Python 2.7 applications.</p>
|
|
<p>Heroku allows you to run as many Python web applications as you like, 24/7 and free
|
|
of charge. Heroku is best described as a horizontal scaling platform. They start
|
|
to charge you once you “scale” you application to run on more than one Dyno
|
|
(abstacted servers) at a time.</p>
|
|
<p>Heroku publishes <a class="reference external" href="http://devcenter.heroku.com/articles/python">step-by-step instructions</a> on how to set up your first
|
|
application for use in Heroku, and maintains a list of <a class="reference external" href="http://python.herokuapp.com/">example applications</a>.</p>
|
|
</div>
|
|
<div class="section" id="dotcloud">
|
|
<h4>DotCloud<a class="headerlink" href="#dotcloud" title="Permalink to this headline">¶</a></h4>
|
|
<p><a class="reference external" href="http://www.dotcloud.com/">DotCloud</a> supports WSGI applications and
|
|
background/worker tasks natively on their platform. Web applications running
|
|
Python version 2.6, and uses <a class="reference internal" href="#nginx-ref"><em>nginx</em></a> and <a class="reference internal" href="#uwsgi-ref"><em>uWSGI</em></a>, and allows custom configuration of both
|
|
for advanced users.</p>
|
|
<p>DotCloud uses a custom command-line API client which can work with
|
|
applications managed in git repositories or any other version control
|
|
system.</p>
|
|
<p>DotCloud has a free plan with limited database size, and without extra
|
|
services (caching…).</p>
|
|
<p>See the <a class="reference external" href="http://docs.dotcloud.com/services/python/">DotCloud documentation on Python</a> for more information and help
|
|
getting started.</p>
|
|
</div>
|
|
<div class="section" id="ep-io">
|
|
<h4>ep.io<a class="headerlink" href="#ep-io" title="Permalink to this headline">¶</a></h4>
|
|
<p><a class="reference external" href="https://www.ep.io/">ep.io</a> is a PaaS designed specifically for Python web
|
|
applications. It supports Python versions 2.6 and 2.7, and has Pythonic
|
|
integrations with a variety of services.</p>
|
|
<p>ep.io has a free plan with bandwidth and disk space limitations. Also, in the
|
|
free plan, the web process is only loaded when needed. This means that the
|
|
first request after some inactivity may take up to 15 seconds.</p>
|
|
<p>ep.io publishes <a class="reference external" href="https://www.ep.io/docs/quickstart/">step-by-step instructions</a> on how to get started with their
|
|
platform and how to deploy Django, Flask, or generic WSGI applications.</p>
|
|
<p>ep.io is currently in invite-only beta.</p>
|
|
</div>
|
|
<div class="section" id="gondor">
|
|
<h4>Gondor<a class="headerlink" href="#gondor" title="Permalink to this headline">¶</a></h4>
|
|
<p><a class="reference external" href="https://gondor.io/">Gondor</a> is a PaaS specailized for deploying Django
|
|
and Pinax applications. Gondor supports Django versions 1.2 and 1.3 on
|
|
Python version 2.7, and can automatically configure your Django site if you
|
|
use <tt class="docutils literal"><span class="pre">local_settings.py</span></tt> for site-specific configuration information.</p>
|
|
<p>Gondor publishes guides to deploying <a class="reference external" href="https://gondor.io/support/setting-up-django/">Django projects</a> and <a class="reference external" href="https://gondor.io/support/setting-up-pinax/">Pinax projects</a> on their platform.</p>
|
|
<p class="rubric">References</p>
|
|
<table class="docutils footnote" frame="void" id="id11" rules="none">
|
|
<colgroup><col class="label" /><col /></colgroup>
|
|
<tbody valign="top">
|
|
<tr><td class="label">[1]</td><td><a class="reference external" href="http://blog.dscpl.com.au/2010/06/modpython-project-is-now-officially.html">The mod_python project is now officially dead</a></td></tr>
|
|
</tbody>
|
|
</table>
|
|
<table class="docutils footnote" frame="void" id="id12" rules="none">
|
|
<colgroup><col class="label" /><col /></colgroup>
|
|
<tbody valign="top">
|
|
<tr><td class="label">[2]</td><td><a class="reference external" href="http://www.modpython.org/pipermail/mod_python/2007-July/024080.html">mod_wsgi vs mod_python</a></td></tr>
|
|
</tbody>
|
|
</table>
|
|
<table class="docutils footnote" frame="void" id="id13" rules="none">
|
|
<colgroup><col class="label" /><col /></colgroup>
|
|
<tbody valign="top">
|
|
<tr><td class="label"><a class="fn-backref" href="#id4">[3]</a></td><td><a class="reference external" href="http://nichol.as/benchmark-of-python-web-servers">Benchmark of Python WSGI Servers</a></td></tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="sphinxsidebar">
|
|
<div class="sphinxsidebarwrapper"><h3><a href="http://python-guide.org">Python Guide</a></h3>
|
|
<p>
|
|
This opinionated guide exists to provide both novice and expert Python developers a best-practice handbook to the installation, configuration, and usage of Python on a daily basis.
|
|
</p>
|
|
<h3><a href="../index.html">Table Of Contents</a></h3>
|
|
<ul>
|
|
<li><a class="reference internal" href="#">Web Applications</a><ul>
|
|
<li><a class="reference internal" href="#context">Context</a><ul>
|
|
<li><a class="reference internal" href="#wsgi">WSGI</a></li>
|
|
</ul>
|
|
</li>
|
|
<li><a class="reference internal" href="#frameworks">Frameworks</a><ul>
|
|
<li><a class="reference internal" href="#django">Django</a></li>
|
|
<li><a class="reference internal" href="#flask">Flask</a></li>
|
|
</ul>
|
|
</li>
|
|
<li><a class="reference internal" href="#web-servers">Web Servers</a><ul>
|
|
<li><a class="reference internal" href="#nginx">Nginx</a></li>
|
|
</ul>
|
|
</li>
|
|
<li><a class="reference internal" href="#wsgi-servers">WSGI Servers</a><ul>
|
|
<li><a class="reference internal" href="#gunicorn">Gunicorn</a></li>
|
|
</ul>
|
|
</li>
|
|
<li><a class="reference internal" href="#server-best-practices">Server Best Practices</a></li>
|
|
<li><a class="reference internal" href="#hosting">Hosting</a><ul>
|
|
<li><a class="reference internal" href="#platform-as-a-service">Platform-as-a-Service</a><ul>
|
|
<li><a class="reference internal" href="#heroku">Heroku</a></li>
|
|
<li><a class="reference internal" href="#dotcloud">DotCloud</a></li>
|
|
<li><a class="reference internal" href="#ep-io">ep.io</a></li>
|
|
<li><a class="reference internal" href="#gondor">Gondor</a></li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
<h3>Related Topics</h3>
|
|
<ul>
|
|
<li><a href="../index.html">Documentation overview</a><ul>
|
|
<li>Previous: <a href="../writing/license.html" title="previous chapter">Choosing a License</a></li>
|
|
<li>Next: <a href="cli.html" title="next chapter">Command Line Applications</a></li>
|
|
</ul></li>
|
|
</ul>
|
|
<h3>This Page</h3>
|
|
<ul class="this-page-menu">
|
|
<li><a href="../_sources/scenarios/web.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>
|
|
<div class="clearer"></div>
|
|
</div>
|
|
<div class="footer">
|
|
© Copyright 2012. A <a href="http://kennethreitz.com/pages/open-projects.html">Kenneth Reitz</a> Project. <a href="http://creativecommons.org/licenses/by-sa/3.0/"> Creative Commons Share-Alike 3.0</a>..
|
|
</div>
|
|
<a href="https://github.com/kennethreitz/python-guide" class="github">
|
|
<img style="position: absolute; top: 0; right: 0; border: 0;" src="http://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub" />
|
|
</a>
|
|
|
|
<script type="text/javascript" src="//www.hellobar.com/hellobar.js"></script>
|
|
<script type="text/javascript">
|
|
new HelloBar(36402,48802);
|
|
</script>
|
|
|
|
<script type="text/javascript">
|
|
|
|
var _gaq2 = _gaq2 || [];
|
|
_gaq2.push(['_setAccount', 'UA-8742933-10']);
|
|
_gaq2.push(['_setDomainName', 'none']);
|
|
_gaq2.push(['_setAllowLinker', true]);
|
|
_gaq2.push(['_trackPageview']);
|
|
|
|
(function() {
|
|
var ga2 = document.createElement('script'); ga.type = 'text/javascript'; ga2.async = true;
|
|
ga2.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
|
|
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga2, s);
|
|
})();
|
|
|
|
</script>
|
|
|
|
<script type="text/javascript">
|
|
(function() {
|
|
var t = document.createElement('script');
|
|
t.type = 'text/javascript';
|
|
t.async = true;
|
|
t.id = 'gauges-tracker';
|
|
t.setAttribute('data-site-id',
|
|
'4ddc1cfaf5a1f50fcc000001');
|
|
t.src = '//secure.gaug.es/track.js';
|
|
var s = document.getElementsByTagName('script')[0];
|
|
s.parentNode.insertBefore(t, s);
|
|
})();
|
|
</script>
|
|
</body>
|
|
</html> |