Flask Documentation (1.1.x)
Support Template Rendering Configuration Stream Helpers Useful Internals Signals Class-Based Views URL Route Registrations View Function Options Command Line Interface Additional Notes Design notes, legal Flask application looks something like this: from flask import Flask app = Flask(__name__) @app.route('/') def hello_world(): return 'Hello, World!' So what did that code do? 1. First we imported files, and so on. For more information have a look at the Flask documentation. 3. We then use the route() decorator to tell Flask what URL should trigger our function. 4. The function is given a name0 码力 | 428 页 | 895.98 KB | 1 年前3Flask Documentation (1.1.x)
Flask application looks something like this: from flask import Flask app = Flask(__name__) @app.route('/') def hello_world(): return 'Hello, World!' So what did that code do? 1. First we imported the files, and so on. For more information have a look at the Flask documentation. 3. We then use the route() decorator to tell Flask what URL should trigger our function. 4. The function is given a name which remember and use to directly visit a page. Use the route() decorator to bind a function to a URL. @app.route('/') def index(): return 'Index Page' @app.route('/hello') (continues on next page) 10 Chapter0 码力 | 291 页 | 1.25 MB | 1 年前3Flask入门教程
。当用户访问根地址的时候,我们需要返回一行欢迎文字。这个任 务只需要下面几行代码就可以完成: app.py:程序主页 from flask import Flask app = Flask(__name__) @app.route('/') def hello(): return 'Welcome to My Watchlist!' 按照惯例,我们把程序保存为 app.py,确保当前目录是项目的根目录,然后在命令 所谓的“注册”,就是给这个函数戴上一个装饰器帽子。我们使用 app.route() 装 饰器来为这个函数绑定对应的 URL,当用户在浏览器访问这个 URL 的时候,就会 触发这个函数,获取返回值,并把返回值显示到浏览器窗口: @app.route('/') def hello(): return 'Welcome to My Watchlist!' 填入 app.route() 装饰器的第一个参数是 URL 修改视图函数返回值 首先,你可以自由修改视图函数的返回值,比如: @app.route('/') def hello(): return u'欢迎来到我的 Watchlist!' 返回值作为响应的主体,默认会被浏览器作为 HTML 格式解析,所以我们可以添加 一个 HTML 元素标记: @app.route('/') def hello(): return 'Hello
0 码力 | 127 页 | 7.62 MB | 1 年前3Flask-RESTful Documentation Release 0.3.6
Flask-RESTful will call the handle_error() function on any 400 or 500 error that happens on a Flask-RESTful route, and leave other routes alone. You may want your app to return an error message with the correct media endpoint (str) – endpoint name (defaults to Resource.__name__.lower() Can be used to reference this route in fields.Url fields • resource_class_args (tuple) – args to be forwarded to the constructor of the0 码力 | 46 页 | 245.60 KB | 1 年前3Flask-RESTful Documentation Release 0.3.6
Flask-RESTful will call the handle_error() function on any 400 or 500 error that happens on a Flask-RESTful route, and leave other routes alone. You may want your app to return an error message with the correct media endpoint (str) – endpoint name (defaults to Resource.__name__.lower() Can be used to reference this route in fields.Url fields resource_class_args (tuple) – args to be forwarded to the constructor of the0 码力 | 49 页 | 91.90 KB | 1 年前3Flask-RESTful Documentation Release 0.3.7
Flask-RESTful will call the handle_error() function on any 400 or 500 error that happens on a Flask-RESTful route, and leave other routes alone. You may want your app to return an error message with the correct media endpoint (str) – endpoint name (defaults to Resource.__name__.lower() Can be used to reference this route in fields.Url fields • resource_class_args (tuple) – args to be forwarded to the constructor of the0 码力 | 50 页 | 253.09 KB | 1 年前3Flask-RESTful Documentation Release 0.3.8
Flask-RESTful will call the handle_error() function on any 400 or 500 error that happens on a Flask-RESTful route, and leave other routes alone. You may want your app to return an error message with the correct media endpoint (str) – endpoint name (defaults to Resource.__name__.lower() Can be used to reference this route in fields.Url fields • resource_class_args (tuple) – args to be forwarded to the constructor of the0 码力 | 50 页 | 253.64 KB | 1 年前3Flask-RESTful Documentation Release 0.3.8
Flask-RESTful will call the handle_error() function on any 400 or 500 error that happens on a Flask-RESTful route, and leave other routes alone. You may want your app to return an error message with the correct media .html#str]) – endpoint name (defaults to Resource.__name__.lower() Can be used to reference this route in fields.Url fields resource_class_args (tuple [https://docs.python.org/3/library/stdtypes.html#tuple])0 码力 | 55 页 | 93.30 KB | 1 年前3Flask-RESTful Documentation Release 0.3.7
Flask-RESTful will call the handle_error() function on any 400 or 500 error that happens on a Flask-RESTful route, and leave other routes alone. You may want your app to return an error message with the correct media .html#str]) – endpoint name (defaults to Resource.__name__.lower() Can be used to reference this route in fields.Url fields resource_class_args (tuple [https://docs.python.org/3/library/stdtypes.html#tuple])0 码力 | 55 页 | 93.21 KB | 1 年前3Flask-RESTful Documentation Release 0.3.10
Flask-RESTful will call the handle_error() function on any 400 or 500 error that happens on a Flask-RESTful route, and leave other routes alone. You may want your app to return an error message with the correct media0 码力 | 42 页 | 84.60 KB | 1 年前3
共 11 条
- 1
- 2