我最近开始学习Flask框架,并编写了一个简短的程序来理解Flask中的request/response
循环。在
我的问题是最后一个名为calc
的方法不起作用。在
我以以下身份发送请求:
我得到了错误:
"Not Found: The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again."
以下是我的烧瓶应用程序代码:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
return "<h1>Hello, World!</h1>"
@app.route('/user/<name>')
def user(name):
return '<h1>Hello, {0}!</h1>'.format(name)
@app.route('/math/calculate/<string:var1>/<int:var2>')
def calc(var1, var2):
return '<h1>Result: {0}!</h1>'.format(int(var1)+int(var2))
if __name__ == '__main__':
app.run(host='0.0.0.0', port=80, debug=True)
要访问评论中描述的请求参数,可以使用请求库:
此方法的文档记录如下:
http://flask.pocoo.org/docs/1.0/api/#flask.Request.args
从中提取密钥值的get方法原型请求.args是:
获取(键,默认值=无,类型=无)
相关问题 更多 >
编程相关推荐