2017-06-03 92 views
-1

我在HTML中有一个非常简单的提交按钮,但它不起作用。最简单的按钮不起作用

main_page.html

<form class="main_page" method="POST" action="."> 
    <div class="form-row"> 
     <input type="submit" name="invoer" value="Invoeren"/> 
    </div> 
</form> 

flask_app.py

from flask import Flask, render_template, request 

app = Flask(__name__) 
app.config["DEBUG"] = True 

@app.route("/", methods=["GET", "POST"]) 

def main(): 
    if request.method == "GET": 
     return render_template("main_page.html") 

    if request.form["invoer"] == "POST": 
     return render_template("main_page.html") 

当我按一下按钮,它表明我:

------ -------------------------------------------------- -------------------------------------------------- ------------------------- - https://i.gyazo.com/65bb8c9fa02d007a8ed8d3d465412e4f.png


我已经犯了这样的一个按钮之前,但当时它的工作,也许我做了一些不同的东西。我该怎么办?

+1

1.你看过日志的时候,和2.是否真的是你的HTML?这显然是坏的。 – jonrsharpe

+0

1.是的,我已经这样做了,但它给了我这个https://pastebin.com/pZE0KY3E,我不知道为什么以及它意味着什么。 2. HTML只是完整html文件的一部分,我添加了复制时错过的''''。为什么downvote .... – Jip1912

+0

把[mcve] *放在问题*中。 – jonrsharpe

回答

1

错误显示ValueError: View function did not return a response,这意味着当您单击HTML中的提交按钮时,您的POST没有返回任何对模板的响应。 Chagne代码flask_app.py到:

from flask import Flask, render_template, request 

app = Flask(__name__) 
app.config["DEBUG"] = True 

@app.route("/", methods=["GET", "POST"]) 

def main(): 
    if request.method == "GET": 
     return render_template("main_page.html") 

    if request.method == "POST": # change code here 
     return render_template("main_page.html") 

这将使得它的工作原理,但是,它会返回一样的模板。

+0

这就是我需要的!谢谢:) – Jip1912

+0

@ Jip1912如果是解决方案,请标记为接受答案,谢谢:) –