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><ahref="https://www.airpair.com/python/posts/django-flask-pyramid">Django vs Flask vs Pyramid: Choosing a Python Web Framework</a>
contains background information and code comparisons for similar
web applications built in these three big Python frameworks.</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>
<li>
<p><ahref="http://www.reddit.com/r/webdev/comments/2les4x/what_frameworks_do_you_use_and_why_are_they/">What web frameworks do you use and why are they awesome?</a>
is a language agnostic Reddit discussion on web frameworks. It's interesting
to see what programmers in other languages like and dislike about their
suite of web frameworks compared to the main Python frameworks.</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 set up a Django (1.5, 1.6, or /1.7) project from scratch?”</p>
explains what happens when you visit a webpage generated by Django.</p>
</li>
<li>
<p><ahref="http://www.caktusgroup.com/blog/2014/11/10/Using-Amazon-S3-to-store-your-Django-sites-static-and-media-files/">Using Amazon S3 to Store your Django Site's Static and Media Files</a>
is a well written guide to a question commonly asked about static and
media file serving.</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>
</li>
<li>
<p><ahref="http://gettingstartedwithdjango.com/">Getting Started with Django</a> is a
series of video tutorials for the framework.</p>
</li>
<li>
<p>The videos and slides from
<ahref="http://www.djangounderthehood.com/talks/">Django: Under the Hood 2014</a>
are from Django core commiters and provide insight into the ORM,
internationalization, templates and other topics.</p>
<h2>Django with Angular (Djangular) resources</h2>
<ul>
<li>
<p><ahref="http://blog.kevinastone.com/getting-started-with-django-rest-framework-and-angularjs.html">Getting Started with Django Rest Framework and AngularJS</a>
is a very detailed introduction to Djangular with example code. </p>
</li>
<li>
<p><ahref="https://thinkster.io/brewer/angular-django-tutorial/">Building Web Applications with Django and AngularJS</a>
is a very detailed guide for using Django as an API layer and AngularJS
as the MVC front end in the browser.</p>
</li>
<li>
<p>This <ahref="http://blog.mourafiq.com/post/55034504632/end-to-end-web-app-with-django-rest-framework">end to end web app with Django-Rest-Framework & AngularJS part 1</a>
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>If you're looking for a fun introduction to Flask and WebSockets, check out
my blog post on creating
<ahref="https://www.twilio.com/blog/2014/11/choose-your-own-adventure-presentations-with-reveal-js-python-and-websockets.html">Choose Your Own Adventure Presentations with Reveal.js, Python and WebSockets</a>.
That post is my favorite technical walkthrough I've written to date. There
for the app with tags for each step in the blog post.</p>
</li>
<li>
<p><ahref="https://www.twilio.com/blog/2014/10/branded-mms-coupon-generation-with-python-and-twilio.html">Branded MMS Coupon Generation with Python and Twilio</a>
is a Flask tutorial I wrote for building a web application that can send
branded barcode coupons via MMS. The post goes through every step from
a blank directory until you have a working app that you can deploy to
Heroku.</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><ahref="http://charlesleifer.com/blog/saturday-morning-hacks-building-an-analytics-app-with-flask/">Building an Analytics App with Flask</a>
is a detailed walkthrough for collecting and analyzing webpage
analytics with your own Flask app.</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>
shows how to build a task queue with Flask and Redis.</p>
</li>
<li>
<p>Along with the above FLask by Example series, there's also a
<ahref="https://github.com/realpython/discover-flask">Discover Flask</a> series of
videos. The GitHub repo contains the code and the 25+ videos are hosted
on YouTube.</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="http://blog.miguelgrinberg.com/post/video-streaming-with-flask">Video streaming with Flask</a>
is another fantastic tutorial by Miguel Grinberg that covers video
streaming.</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><ahref="https://github.com/changhiskhan/poseidon">Poseidon</a> is a Python commandline
interface for managing Digital Ocean droplets (servers).</p>
</li>
<li>
<p>Rackspace also has <ahref="http://docs.rackspace.com/sdks/guide/content/python.html">official documentation for Python</a>.</p>