|Charles Reid e3b3c215b4||1 year ago|
|Readme.md||1 year ago|
|requirements.txt||1 year ago|
|simple.py||1 year ago|
|test_simple.py||1 year ago|
Flask home page: http://flask.pocoo.org/
Here is the simplest Flask app:
from flask import Flask app = Flask(__name__) @app.route("/") def hello(): return "Hello World!"
This directory contains files to get this server up and running.
Create a virtual environment, which we’ll call
vp (you can use any name you want):
This creates a “clean” version of
pip that are separate from your
normal version of Python and pip.
To install Flask into this virtual environment:
pip install -r requirements.txt
requirements.txt file just contains the name of any Python packages
that should be installed, and optional version numbers. In this case, we
only install Flask, so the contents of
The Flask web application is stored in the variable
To run the Flask app, you call
To test the simple Flask web app, you can use the Python
unittest module from
the command line:
python -m unittest discover
This will find and run the Flask test.
To run a Flask test, you only need to create the test client - the server is taken
care of for you.
client = app.test_client()
This is a built-in Flask method that returns a client object.
The client object can run get and post methods on URLs.
The simple server only needs get methods to test routes:
# Test route / r = client.get('/') assert b'Hello world!' in r.data