September 2017
Intermediate to advanced
206 pages
4h 34m
English
Flask is a simple web framework based on Werkzeug. It's easy to build HTTP GET/POST requests. If you have a scenario where you want to develop a RESTful server, Flask can solve your problem fast. The official website of Flask is http://flask.pocoo.org. You can install Flask using pip. Type this command:
$ pip install Flask
For testing, we can create a simple-to-handle HTTP GET request. Create a Python file, called ch04_flask.py. Write the following program:
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello,Flask!"
@app.route('/ads/<int:ads_id>')
def show_post(ads_id):
return 'Adversiting id %d' % ads_id
This program will handle HTTP GET requests: / and /ads/<id>.
To run the program, you can type ...
Read now
Unlock full access