You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.
Dismiss alert
<metaname="description" content="Full Stack Python explains each layer of the web application stack, from the server up through the rendering in a user's browser.">
<p>You're knee deep in learning the <ahref="http://www.python.org/">Python</a>
programming language. The syntax is starting to make sense. The first
few "<em>ahh-ha</em>!" moments are hitting you as you're learning conditional
statements, for loops and classes while playing around with the open source
libraries that make Python such an amazing language.</p>
<p>Now you want to take your initial Python knowledge and make something real.
A real web application that's available on the web which you can show off or
sell as a service to other people. That's where Full Stack Python comes in.
You've come to the right place to learn everything you need to deploy and
run a production Python web application.</p>
<p>This guide branches out on topic because your learning needs depend on what
you're currently trying to do. </p>
<h3>Let's get started. What do you need to do right now?</h3>
<h1>Web frameworks</h1>
<p>A web application framework is a code library that makes a developer's life
easier when building reliable, scalable and maintainable web applications.</p>
<h2>Why are web frameworks necessary?</h2>
<p>Web frameworks encapsulate what developers have learned over the past twenty
years while building dynamic web applications. Frameworks make it easier
to reuse code for common HTTP operations and to structure your code so that
it is maintainable.</p>
<h2>Common web framework functionality</h2>
<p>Frameworks provide functionality in their code or through extensions to
perform common operations required to run web applications. These common
operations include:</p>
<ol>
<li>URL routing</li>
<li>HTML, XML, JSON, and other output format templating</li>
<li>Database manipulation</li>
<li>Security against Cross-site request forgery (CSRF) and other attacks</li>
</ol>
<p>Not all web frameworks include code for all of the above
functionality. Frameworks fall somewhere between simply executing a
single use case and attempting to be everything to every developer with
increased complexity. Some frameworks take the "batteries-included" approach
where everything possible comes bundled with the framework while others
have a minimal code library that plays well with extensions.</p>
<p>For example, the Django web application framework includes an
Object-Relational Mapping (ORM) layer that abstracts relational database
read, write, query, and delete operations. However, Django's ORM
cannot work without significant modification on non-relational databases such as
<ahref="http://www.mongodb.org/">MongoDB</a>.
Some other web frameworks such as Flask and Pyramid are easier to
use with non-relational databases by incorporating external Python libraries.
There is a spectrum between minimal functionality with easy extensibility and
including everything in the framework with tight integration.</p>
<h2>General web framework resources</h2>
<ul>
<li>
<p>"<ahref="http://www.jeffknupp.com/blog/2014/03/03/what-is-a-web-framework/">What is a web framework?</a>"
by <ahref="https://twitter.com/jeffknupp">Jeff Knupp</a>
is an in-depth explanation of what a web framework is and their relation
to web servers.</p>
</li>
<li>
<p>Check out the answer to the
"<ahref="http://stackoverflow.com/questions/4507506/what-is-a-web-framework-how-does-it-compare-with-lamp">What is a web framework and how does it compare to LAMP?</a>"
question on Stack Overflow.</p>
</li>
<li>
<p>This <ahref="http://www.konstruktor.ee/blog/python-web-framework-roundup/">Python web framework roundup</a>
covers Django, Flask and Bottle as well as several other lesser known Python
frameworks.</p>
</li>
<li>
<p>This fascinating blog post takes a look at the
<ahref="http://grokcode.com/864/snakefooding-python-code-for-complexity-visualization/">code complexity of several Python web frameworks</a>
by providing visualizations based on their code bases.</p>
</li>
</ul>
<h2>Web frameworks learning checklist</h2>
<p><iclass="fa fa-check-square-o"></i>
Choose a major Python web framework (<ahref="/django.html">Django</a> or
<ahref="/flask.html">Flask</a> are recommended) and stick with it. When you're just
starting it's best to learn one framework first instead of bouncing around
trying to understand every framework. </p>
<p><iclass="fa fa-check-square-o"></i>
Work through a detailed tutorial found within the resources links on the
framework's page.</p>
<p><iclass="fa fa-check-square-o"></i>
Study open source examples built with your framework of choice so you can
take parts of those projects and reuse the code in your application.</p>
<p><iclass="fa fa-check-square-o"></i>
Build the first simple iteration of your web application then go to
the <ahref="/deployment.html">deployment</a> section to make it accessible on the
web.</p>
<h3>Which web framework do you want to learn about?</h3>
<h1>Django</h1>
<p><ahref="http://www.djangoproject.com/">Django</a> is a widely used Python web
application framework with a "batteries-included" philosophy. The principle
behind batteries-included is that the common functionality for building
web applications should come with the framework instead of as separate
has several nice examples for breaking Django into smaller simplier
components.</p>
</li>
<li>
<p>The <ahref="https://github.com/rogueleaderr/definitive_guide_to_django_deployment">Definitive Guide to Django Deployment</a>
explains the architecture of the resulting set up and includes Chef scripts
to automate the deployment.</p>
</li>
<li>
<p><ahref="http://agiliq.com/blog/2014/08/deploying-a-django-app-on-amazon-ec2-instance/">Deploying a Django app on Amazon EC2 instance</a>
is a detailed walkthrough for deploying an example Django app to Amazon
Web Services.</p>
</li>
<li>
<p>This <ahref="http://aliteralmind.wordpress.com/2014/09/21/jquery_django_tutorial/">step-by-step guide for Django</a>
shows how to transmit data via AJAX with JQuery.</p>
</li>
<li>
<p><ahref="http://www.nickpolet.com/blog/deploying-django-on-aws/1/">Deploying Django on AWS</a>
is another walkthrough for deploying Django to AWS.</p>
</li>
<li>
<p><ahref="https://github.com/rosarior/awesome-django">django-awesome</a> is a curated
list of Django libraries and resources.</p>
</li>
<li>
<p><ahref="https://realpython.com/learn/start-django/">Starting a Django Project</a> answers the question, “How do I setup a Django (1.5, 1.6, or 1.7) Project from scratch?”</p>
</li>
</ul>
<h2>Django videos</h2>
<ul>
<li>
<p>Kate Heddleston and I gave a talk at DjangoCon 2014 called
<ahref="https://www.youtube.com/watch?v=QrFEKghISEI">Choose Your Own Django Deployment Adventure</a>
which walked through many of the scenarios you'd face when deploying your
first Django website.</p>
</li>
<li>
<p><ahref="https://godjango.com/">GoDjango</a> screencasts and tutorials are free short
videos for learning how to build Django applications.</p>
Build a few more simple applications using the tutorial resources found
in the "Django resources" section.</p>
<p><iclass="fa fa-check-square-o"></i>
Start coding your own Django project with help from the
<ahref="https://docs.djangoproject.com/en/dev/">official documentation</a> and
resource links below. You'll make plenty of mistakes which is critical
on your path to learning the right way to build applications.</p>
<p><iclass="fa fa-check-square-o"></i>
Read <ahref="http://www.amazon.com/Two-Scoops-Django-Best-Practices/dp/098146730X/ref=sr_1_2?ie=UTF8&qid=1391562062&sr=8-2&tag=mlinar-20">2 Scoops of Django</a>
to understand Django best practices and learn better ways of building
Django web applications.</p>
<p><iclass="fa fa-check-square-o"></i>
Move on to the <ahref="/deployment.html">deployment section</a> to get your Django
project on the web.</p>
<h3>What do you need to learn next for your Django app?</h3>
<h1>Flask</h1>
<p><ahref="http://flask.pocoo.org/">Flask</a> is a Python web framework built with a
<ahref="http://flask.pocoo.org/docs/design/">small core and easy-to-extend philosophy</a>.
<li><ahref="http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-xvi-debugging-testing-and-profiling">Part 16: Debugging, Testing and Profiling</a></li>
<li><ahref="http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-xvii-deployment-on-linux-even-on-the-raspberry-pi">Part 17: Deployment on Linux</a></li>
<li>
<p><ahref="http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-xviii-deployment-on-the-heroku-cloud">Part 18: Deployment on the Heroku Cloud</a></p>
</li>
<li>
<p><ahref="http://blog.john.mayonvolcanosoftware.com/building-a-blog-using-flask-and-angularjs-part-1/">Building a blog using Flask and AngularJS Part 1</a>
is the first of a multipart series on working with Flask and an AngularJS
front end.
<ahref="http://blog.john.mayonvolcanosoftware.com/building-a-blog-using-flask-and-angularjs-part-2/">Part 2</a> is also available
<ahref="https://github.com/basco-johnkevin/building-a-blog-using-flask-and-angularjs">along with the source code</a>.</p>
</li>
<li>
<p><ahref="http://flask.pocoo.org/extensions/">The Flask Extensions Registry</a> is a
curated list of the best packages that extend Flask. It's the first location
to look through when you're wondering how to do something that's not in the
core framework.</p>
</li>
<li>
<p><ahref="http://exploreflask.com/">Explore Flask</a> is a public domain book that
was previously backed on Kickstarter and cost money for about a year before
being open sourced. The book explains best practices and patterns for
building Flask apps.</p>
</li>
<li>
<p>Randall Degges wrote a detailed walkthrough for
<ahref="https://stormpath.com/blog/build-a-flask-app-in-30-minutes/">building a Flask app in 30 minutes</a>.</p>
</li>
<li>
<p>Nice post by Jeff Knupp on <ahref="http://www.jeffknupp.com/blog/2014/01/29/productionizing-a-flask-application/">Productionizing a Flask App</a>.</p>
</li>
<li>
<p><ahref="http://maximebf.com/blog/2012/10/building-websites-in-python-with-flask/#.U06EZ-ZdW4J">Building Websites in Python with Flask</a>
is another walkthrough tutorial from first steps through
<ahref="http://maximebf.com/blog/2012/11/getting-bigger-with-flask/">getting bigger with Flask</a>.</p>
</li>
<li>
<p>The Plank & Whittle blog has two posts, one on
<ahref="http://www.plankandwhittle.com/packaging-a-flask-web-app/">Packaging a Flask web app</a>
and another on
<ahref="http://www.plankandwhittle.com/packaging-a-flask-app-in-a-debian-package/">Packaging a Flask app in a Debian package</a>
once you've built an app and want to deploy it.</p>
is also now online that shows how to use PostgreSQL, SQLAlchemy and Alembic.</p>
</li>
<li>
<p><ahref="https://www.digitalocean.com/community/articles/how-to-structure-large-flask-applications">How to Structure Large Flask Applications</a>
covers a subject that comes up quickly once you begin adding significant
functionality to your Flask application.</p>
</li>
<li>
<p>"<ahref="https://medium.com/@5hreyans/the-one-weird-trick-that-cut-our-flask-page-load-time-by-70-87145335f679">One line of code cut our Flask page load times by 60%</a>
is an important note about optimizing Flask template cache size to
dramatically increase performance in some cases.</p>
</li>
<li>
<p><ahref="https://www.twilio.com/blog/2014/03/unit-testing-your-twilio-app-using-pythons-flask-and-nose.html">Unit Testing Your Twilio App Using Python’s Flask and Nose</a>
covers integrating the Twilio API into a Flask application and how to test
that functionality with <ahref="https://nose.readthedocs.org/en/latest/">nose</a>.</p>
</li>
<li>
<p>The Flask documentation has some quick examples for how to deploy Flask
provides a thorough view of basic concepts and features for the framework.</p>
</li>
<li>
<p>Digital Ocean provides an extensive <ahref="https://www.digitalocean.com/community/articles/how-to-use-the-bottle-micro-framework-to-develop-python-web-apps">introductory post on Bottle</a>.</p>
</li>
<li>
<p>This tutorial provides a walkthrough for
<ahref="http://www.giantflyingsaucer.com/blog/?p=3598">getting started with Bottle</a>.</p>
</li>
<li>
<p>Here's a short code snippet for
<ahref="http://myadventuresincoding.wordpress.com/2011/01/02/creating-a-rest-api-in-python-using-bottle-and-mongodb/">creating a RESTful API with Bottle and MongoDB</a>.</p>
presentation goes over Bottle, Flask, and many other lesser known Python
web frameworks.</p>
</li>
<li>
<p>A Python newcomer asked the Python Subreddit to
<ahref="http://www.reddit.com/r/Python/comments/28qr7c/can_anyone_explain_the_differences_between_web2py/">explain the differences between numerous Python web frameworks</a>
and received some interesting responses from other users.</p>
</li>
</ul>
<h2>Other frameworks learning checklist</h2>
<p><iclass="fa fa-check-square-o"></i>
Read through the web frameworks listed above and check out their project
websites. </p>
<p><iclass="fa fa-check-square-o"></i>
It's useful to know what other web frameworks exist besides Django and Flask.
However, when you're just starting to learn to program there are significantly
more tutorials and resources for <ahref="/django.html">Django</a> and
<ahref="/flask.html">Flask</a> on the web. My recommendation is to start with one of
those two frameworks then expand your knowledge from there.</p>
<h3>What do you need to learn next?</h3>
<h1>Deployment</h1>
<p>Deployment involves packaging up your web application and putting it in a
production environment that can run the app.</p>
<h2>Why is deployment necessary?</h2>
<p>Your web application must live somewhere other than your own desktop or
laptop. A production environment is the canonical version of your current
application and its associated data.</p>
<h2>Deployment topics map</h2>
<p>Python web application deployments are comprised of many pieces that need to
be individually configured. Here is a map that visually depicts how each
deployment topic relates to each other. Click the image to pull up a PDF
<p>The disadvantage to IaaS platforms is the lock-in if you have to write
custom code to deploy, dynamically scale, and generally understand your
infrastructure. Every platform has its quirks. For example,
Amazon's standard <ahref="http://aws.amazon.com/ebs/">Elastic Block Store</a> storage
infrastructure has at least an order of magnitude worse I/O throughput
than working with your local disk. Your application's database queries may
work great locally but then when you deploy the performance is inadequate.
Amazon has <ahref="http://aws.amazon.com/about-aws/whats-new/2012/07/31/announcing-provisioned-iops-for-amazon-ebs/">higher throughput EBS instances</a>
but you will pay correspondingly more for them. EBS throughput is just
one of many quirks you need to understand before committing to an
IaaS platform.</p>
<h3>Infrastructure-as-a-service resources</h3>
<ul>
<li>
<p><ahref="http://www.screamingatmyscreen.com/2012/12/the-cloud-vs-dedicated-servers/">The cloud versus dedicated servers</a></p>
</li>
<li>
<p><ahref="https://www.digitalocean.com/community/articles/5-common-server-setups-for-your-web-application">5 common server setups for your web application</a>
is a great introduction to how hosting can be arranged.</p>
</li>
<li>
<p><ahref="http://libcloud.apache.org/">Apache Libcloud</a> is a Python library that
provides a unified API for many cloud service providers.</p>
</li>
<li>
<p><ahref="http://aws.amazon.com/python/">Amazon Web Services has official documentation</a> for running Python web applications.</p>
</li>
<li>
<p><ahref="https://github.com/boto/boto">boto</a> is an extensive and well-tested
Python library for working with Amazon Web Services.</p>
</li>
<li>
<p>Rackspace also has <ahref="http://docs.rackspace.com/sdks/guide/content/python.html">official documentation for Python</a>.</p>
</li>
<li>
<p><ahref="http://feross.org/how-to-setup-your-linode/">How to set up your Linode for maximum awesomeness</a>
shows how to work with a VPS once you've got the server up and running.</p>
</li>
</ul>
<h2>Servers learning checklist</h2>
<p><iclass="fa fa-check-square-o"></i>
Sign up for a hosting provider. I recommend getting a
to set up your initial infrastructure and deploy your web application there.
<ahref="https://www.digitalocean.com/">Digital Ocean</a> and
<ahref="http://prgmr.com/xen/">prgrmr</a> are other VPS options. You can change
hosting providers later after the deployment process is automated.</p>
<p><iclass="fa fa-check-square-o"></i>
Provision your first server. It will be ready but in a shutdown state while
awaiting your instructions.</p>
<p><iclass="fa fa-check-square-o"></i>
Move to the <ahref="/operating-systems.html">operating systems</a> section to learn
how to load Ubuntu 12.04 LTS as a base OS for Python web applications.</p>
<h3>Keep going with setting up a server or try a PaaS?</h3>
<h1>Platform-as-a-service</h1>
<p>A platform-as-a-service (PaaS) provides infrastructure and a software layer
on which a web application is deployed. Running your web application from
a PaaS removes the need to know as much about the underlying servers,
operating system, web server, and often the WSGI server. </p>
<p><em>Note</em>: If you are not interested in deploying to a PaaS you can move
ahead to the <ahref="../wsgi-servers.html">WSGI servers</a> section.</p>
<p>The PaaS layer defines how the application accesses resources such as
computing time, files, and external services. The PaaS provides a
higher-level abstraction for working with computing resources than deploying
an application to a server or IaaS.</p>
<p>A PaaS makes deployment and operations easier because it forces the developer
to conform applications to the PaaS architecture. For example, Heroku looks
for Python's requirements.txt file in the base directory of the repository
during deployment because that is the file's de facto community standard
location.</p>
<p><imgsrc="theme/img/servers-versus-paas.png" width="100%" alt="Traditional LAMP server stack versus a Platform-as-a-Service stack" class="technical-diagram" /></p>
<p>If you go the PaaS route, you can skip configuring an operating system
and web server prebaked into PaaS offerings. PaaS offerings generally start
at the WSGI server layer. </p>
<h2>Platform-as-a-service responsibilities</h2>
<p>Although PaaS offerings simplify setting up and maintaining the servers,
operating system, and web server, developers still have responsibilities for other
layers of their web stack.</p>
<p>While it's useful to know the operating system that underpins your PaaS, for
example Heroku uses Ubuntu 10.04, you will not have to know as much about
securing the operating system and server level. However, web applications deployed
to a PaaS are just as vulnerable to security breaches at the application level
as a standard LAMP stack. It's still your responsibility to ensure the web
application framework and your app itself is up to date and secured. See the
<ahref="../web-application-security.html">security section</a> for further information.</p>
<h2>Platforms-as-a-service that support Python</h2>
<p><ahref="http://appsembler.com/blog/paas-bakeoff-comparing-stackato-openshift-dotcloud-and-heroku-for-django-hosting-and-deployment/">PaaS bakeoff: Comparing Stackato, OpenShift, Dotcloud and Heroku for Django hosting and deployment</a> by <ahref="https://twitter.com/natea">Nate Aune</a>.</p>
</li>
<li>
<p><ahref="http://www.deploydjango.com/">Deploying Django</a> by Randall Degges is