Flask url_for - 传递参数

问题描述

来自两个页面的flask.py文件代码 我正在使用 MysqL 和 Flask 会话。


@app.route("/posts/<title>")
def Post(title):
    cur=MysqL.connection.cursor()
    cur.execute('''SELECT * FROM posts WHERE title=%s''',[title])
    post=cur.fetchone()
    (these statements were put in here just to check if the variables are correctly stored and they are,work perfectly every time I open this page.
    print(post['author'])
    print(post['title'])
    print(session['username'])
    return render_template('posts.html',title=post['title'],post=post)



@app.route("/posts/update",methods=["GET","POST"])
def update_post(title):
    cur=MysqL.connection.cursor()
    cur.execute('''SELECT * FROM posts WHERE title=%s''',[title])
    post=cur.fetchone()
    return render_template('new_post.html',title=title,post=post,legend='Update Post')

HTML <a class="btn btn-secondary btn-sm mt-1 mb-1" href="{{ url_for('update_post',title=post['title']) }}">Update</a>

当我点击这个按钮时它返回一个错误

TypeError: update_post() missing 1 required positional argument: 'title'```

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)