问题描述
我收到一个错误,即无法从 url_for('') 中的该参数构建 URL。
我通过了 url_for('admin') 但这不起作用。我应该通过什么来访问 localhost:5000/admin ?
谢谢
解决方法
您传递要访问的路线的定义名称。
例如:
@app.route('/')
def index():
return 'Hello,World!'
...
@app.route('/some_page')
def somewhere_else():
if something_happened:
redirect(url_for('index'))
return render_template('some_page.html')
或者如果您在 HTML 中使用它:
<a href="{{ url_for('index') }} ...></a>