为什么我提交烧瓶表单时出错?

时间:2020-08-14 12:31:10

标签: python html forms flask

我收到此“表单提交失败! 状态:未找到404 未找到 在服务器上找不到请求的URL。如果您手动输入了网址,请点击拼写,然后重试。”错误,当我在表单上点击“提交”时。

从烧瓶导入烧瓶中的

`,render_template,请求

app = Flask(__name__)

@app.route('/')

def index():
   return render_template("index.html")

@app.route('/', methods=['POST','GET'])
def submit():
  if request.method=="POST":
    name = request.form["name"]
    email = request.form["email"]
    subject = request.form["subject"]
    message = request.form["message"]
    print(name,email,subject,message)
    return render_template("index.html")


if __name__=="__main__":
 app.debug=True
 app.run()

` 请帮忙

1 个答案:

答案 0 :(得分:0)

您的@app.route('/')已用相同的第一个参数重复两次
因此您需要为提交页面指定一个地址(URL),如下所示

@app.route('/submit', methods=['POST','GET'])
def submit():
    #...