Book Image

Learning Python Network Programming

By : Dr. M. O. Faruque Sarker, Samuel B Washington, Sam Washington
Book Image

Learning Python Network Programming

By: Dr. M. O. Faruque Sarker, Samuel B Washington, Sam Washington

Overview of this book

Table of Contents (17 chapters)
Learning Python Network Programming
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Flask – a microframework


To get a taste of working with a Python web framework, we're going to write a small app with Flask. We've chosen Flask because it provides a lean interface, giving us the features we need while getting out of the way and letting us code. Also, it doesn't require any significant preconfiguration, all we need to do is install it, like this:

>>> pip install flask
Downloading/unpacking flask

Flask can also be downloaded from the project's homepage at http://flask.pocoo.org. Note that to run Flask under Python 3, you will need Python 3.3 or higher.

Now create a project directory, and within the directory create a text file called tinyflaskapp.py. Our app is going to allow us to browse the docstrings for the Python built-in functions. Enter this into tinyflaskapp.py:

from flask import Flask, abort
app = Flask(__name__)
app.debug = True

objs = __builtins__.__dict__.items()
docstrings = {name.lower(): obj.__doc__ for name, obj in objs if
              name[0].islower...