gpt4 book ai didi

python - Flask 的 url_for 引发 TypeError : 'function' object has no attribute '__getitem__'

转载 作者:太空宇宙 更新时间:2023-11-04 03:14:33 25 4
gpt4 key购买 nike

我正在尝试为我的详细信息路由生成一个 url 并重定向到它。我调用 redirect(url_for(details)),但得到 TypeError: 'function' object has no attribute '__getitem__'。我做错了什么?

@app.route('/search_process')
def search():
return redirect(url_for(details))

@app.route('/details')
def details():
return 'details'
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/Library/Python/2.7/site-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/Library/Python/2.7/site-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/Library/Python/2.7/site-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/Library/Python/2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Library/Python/2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/Library/Python/2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/Library/Python/2.7/site-packages/flask/app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/Users/Rabbit/PycharmProjects/Final_Project/Final_Project.py", line 59, in search
return redirect(url_for(details))
File "/Library/Python/2.7/site-packages/flask/helpers.py", line 268, in url_for
if endpoint[:1] == '.':

TypeError: 'function' object has no attribute '__getitem__'

最佳答案

您需要将端点名称(一个字符串)传递给 url_for

return redirect(url_for('details'))

关于python - Flask 的 url_for 引发 TypeError : 'function' object has no attribute '__getitem__' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36737170/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com