Tag: Start LAN PoC effect pip install PIP highlight Program Res
Flask is a lightweight WEB application framework written using Python. is also one of the most common frameworks for developing Python Web services.
The first step, of course, is to install flask, which is still PIP installation:
Learning flask can start with the quick start of the website (http://flask.pocoo.org/docs/0.10/quickstart/#hooking-in-wsgi-middlewares), there are many small examples, Let's look at one of the simplest
From flask Import Flaskapp = Flask (__name__) @app. Route ('/') def hello_world (): return ' Hello world! ' if __name__ = = ' __main__ ': app.run (' 172.31.11.141 ', 8080)
This is an adorner implementation of the route function, the table name URL path to "/" Request by Hello_world () processing, and the Hello_world () function simply returned a string. To run the program:
You can also use angle brackets to define variables in the routing path, for example:
@app. Route ('/user/<username> ') def show_user_profile (username): # Show the user profiles for that user Return ' User%s '% username
The effect is as follows:
Of course, flask can also support the processing of static pages, using the first set of static pages of the directory, and then use the App.send_static_file () function to return the static page, the code is as follows:
#-*-Coding:utf-8-*-
From flask import Flaskimport Osapp = Flask (__name__) #设置静态页面的绝对路径app. _static_folder = Os.path.abspath ("/home/yu/flask/ ") @app. Route ('/') def hello_world (): #返回静态页面 return app.send_static_file (' hello.py ')
Python Web Services Learning--flask