pip install flaskflask
from flask import Flask app = Flash(__name__)
@app.route('/') def index(): return ('<h1>Hello World</h1>')
@app.route('/user/<name>') def user(name): return ('<h1>Hello World,%s</h1>')%name
if __name__== '__main__': app.run(debug=True)
变量名 | 上下文 | 说明 |
current_app | 程序上下文 | 当前激活程序的程序实例 |
g | 程序上下文 | 处理请求用做临时存储的对象,每次请求都会重设这个变量 |
request | 请求上下文 | 请求对象,封装了客户端发出的HTTP请求的内容 |
session | 请求上下文 | 用户会话,用于存储请求之间须要“记住”的值得词典 |
before_first_request:注册一个函数,可在处理第一个请求以前运行服务器
before_request:注册一个函数,在每次请求以前运行session
after_request:注册一个函数,若是没有未处理的异常抛出,每次请求以后运行app
teardown_request:注册一个函数,及时有未处理的异常抛出,也在每次请求以后运行框架
安装:pip install flask-script函数
from flask.ext.script import Manager manager = Manager(app) if __name__ == '__main__': manager.run()
hello.py runserver [-h] [-t HOST] [-p PORT] [--threaded] [--processe PROCESSES] [--passthrough-errors] [-d] [-r]url