我试图通过url_for (flask,python3)在一些文本中添加一个链接,并传递一个变量,但都没有成功。我做错了什么吗?html5:
<a class="mr-2" href={{ url_for('user','username'=posts.author)}} >TEXT</a>python3:
@app.route('/user')
def user(username):
print(username)发布于 2020-01-18 03:17:04
您需要将模板代码更改为如下所示:
<a class="mr-2" href="{{ url_for('user',username=posts.author) }}" >TEXT</a>但是,您还必须更改python代码才能使其有效:
@app.route('/user/<username>')
def user(username):
print(username)一个有效的请求现在是:
/user/CodEdo这是假定模板中的posts.author为CodEdo,应该在href中呈现的URL。
https://stackoverflow.com/questions/59793484
复制相似问题