Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 烧瓶按钮错误重定向到索引_Python_Redirect_Flask - Fatal编程技术网

Python 烧瓶按钮错误重定向到索引

Python 烧瓶按钮错误重定向到索引,python,redirect,flask,Python,Redirect,Flask,我有一个输入字段,可以将内容保存到数据库中: {% for comment in comments %} <div class="row"> {{ comment.content }} </div> {% endfor %} <div class="row"> <form action="." method="POST"> <textarea class="form-control"

我有一个输入字段,可以将内容保存到数据库中:

{% for comment in comments %}
    <div class="row">
        {{ comment.content }}
    </div>
{% endfor %}

<div class="row">
    <form action="." method="POST">
        <textarea class="form-control" name="contents" placeholder="Enter a comment"></textarea>
        <input type="submit" class="btn btn-warning" value="save">
    </form>
</div>

return“欢迎来到高射炮”只是一个测试,点击按钮后它仍然会将我重定向到家中。有人能帮我吗?

看来问题出在你的“动作”。将模板中的('show_photography')设置为url\u。

看起来您的“action=“.”是问题所在。将模板中的('show_photography')
设置为url

@app.route('/photography', methods=["GET", "POST"])
def show_photography():
    if request.method == "GET":
        return render_template('photography.html', comments=Comment.query.all())
    elif request.method == "POST":
        comment = Comment(content=request.form["contents"])
        db.sesson.add(comment)
        db.session.commmit()
        return 'welcome to flask!'
    else:
        flash('error message via flash')