http://flask.pocoo.org/docs/1.0/git
Welcome to Flask
Welcome to Flask’s documentation. Get started with Installation and then get an overview with the Quickstart. There is also a more detailed Tutorial that shows how to create a small but complete application with Flask. Common patterns are described in the Patterns for Flask section. The rest of the docs describe each component of Flask in detail, with a full reference in the API section.github
Flask depends on the Jinja template engine and the Werkzeug WSGI toolkit. The documentation for these libraries can be found at:web
還包括sql
http://flask.pocoo.org/docs/1.0/quickstart/#quickstart數據庫
A Minimal Application
A minimal Flask application looks something like this:json
from flask import Flask app = Flask(__name__) @app.route('/') def hello_world(): return 'Hello, World!'
Variable Rules
You can add variable sections to a URL by marking sections with
<variable_name>
. Your function then receives the<variable_name>
as a keyword argument. Optionally, you can use a converter to specify the type of the argument like<converter:variable_name>
.flask@app.route('/user/<username>') def show_user_profile(username): # show the user profile for that user return 'User %s' % username @app.route('/post/<int:post_id>') def show_post(post_id): # show the post with the given id, the id is an integer return 'Post %d' % post_id @app.route('/path/<path:subpath>') def show_subpath(subpath): # show the subpath after /path/ return 'Subpath %s' % subpath
HTTP Methods
Web applications use different HTTP methods when accessing URLs. You should familiarize yourself with the HTTP methods as you work with Flask. By default, a route only answers to
GET
requests. You can use themethods
argument of theroute()
decorator to handle different HTTP methods.apifrom flask import request @app.route('/login', methods=['GET', 'POST']) def login(): if request.method == 'POST': return do_the_login() else: return show_the_login_form()
https://github.com/pallets/flask/tree/1.0.2/examplesapp
包括一個MVC模式的博客栗子,和 js 經過json與後臺交互數據的例子。ide
是學習flask的好資料。
安裝過程遇到問題:
https://cn.bing.com/search?q=sqlite3.OperationalError%3a+no+such+table%3a+post&pc=MOZI&first=1&FORM=PQRE1
須要初始化數據庫, 見樣例的官方文檔說明.
http://flask.pocoo.org/docs/1.0/extensions/#extensions
http://flask.pocoo.org/extensions/
包括 resetful jsonapi 等擴展工具。