我在网上找到的答案是使用request.args.get
。但是,我无法管理它。我有以下简单示例:
from flask import Flask
app = Flask(__name__)
@app.route("/hello")
def hello():
print request.args['x']
return "Hello World!"
if __name__ == "__main__":
app.run()
我127.0.0.1:5000/hello?x=2
在浏览器中转到,结果得到:
Internal Server Error
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.
我究竟做错了什么?
简单的答案是您尚未request
从flask包中导入全局对象。
from flask import Flask, request
通过在调试模式下运行开发服务器,很容易确定自己
app.run(debug=True)
这将为您提供一个堆栈跟踪,包括:
print request.args['x']
NameError: global name 'request' is not defined
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句