'Request'对象没有属性'get'Python错误 [英] 'Request' object has no attribute 'get' Python error
本文介绍了'Request'对象没有属性'get'Python错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用这段代码:
<$ p $ b $控制器= request.get('控制器')
来自瓶子导入请求的url_for,$ p>
但是我得到这个错误:
' Request'对象没有属性'get'
有什么建议?
谢谢
解决方案
您想使用 request.args
。以下是一个来自快速入门文档的访问请求数据部分的示例。 / p>
要访问在URL中提交的参数(?key = value),可以使用args属性:
searchword = request.args.get('key','')
I am trying to get a url parameter in Python.
I am using this code:
from flask import request, url_for, redirect
# ...
controller = request.get('controller')
but I am getting this error:
'Request' object has no attribute 'get'
Any ideas?
Thanks
解决方案
You want to use request.args
for your GET parameters in Flask. Here is a quote with an example from the Accessing Request Data section of the Quickstart document.
To access parameters submitted in the URL (?key=value) you can use the args attribute:
searchword = request.args.get('key', '')
这篇关于'Request'对象没有属性'get'Python错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文