Learning Python Network Programming

(Sean Pound) #1

Applications for the Web


Next you can look at your environment. Are there already preferred packages in
your organization for operations you might want to perform, such as database
access or unit testing? If so, do any frameworks already use these? If not then a
microframework might be a better option, plugging in your required packages.
Do you have a preferred operating system or web server for hosting, and which
frameworks support these? Does your hosting restrict you in terms of Python
version, database technology, or similar? Also, if you have web designers, do you
have time to get them up to speed on a complex templating language, or must it be
kept simple?


Answers to these questions can help you narrow down your choices. Then,
researching the frameworks, asking people who are using them, and trying
out a few likely looking ones will get you where you need to go.


Having said that, for a general web application that needs some user form
submission and database access, you can't really go wrong with Django. It really is
"batteries included", its database model is elegant, and its out-of-the box database
administration and data entry interface is very powerful and can be a huge
timesaver. And for simpler applications such as APIs, Flask is also a great choice,
coupled with SQLAlchemy if database access is needed.


As I mentioned before, there's no right answer, but there's a lot to be learned
by exploring what's available and seeing the different approaches that the
frameworks take.


Of course, once we've got our web application, we need a way to host it. We're going
to look at some options now.


Hosting Python web applications


As we discussed at the beginning of this chapter, in order to run a Python web
application, we need a web server to host it. There are many web servers in existence
today, and you will very likely have heard of several. Popular examples are Apache,
nginx (pronounced engine-x), lhttpd (pronounced lighty), and Microsoft's Internet
Information Services (IIS).


There is a lot of terminology around web servers and various mechanisms they can
use to invoke Python web applications. We're going to take a very brief tour of the
history of web applications to help explain some of these concepts.

Free download pdf