【问题标题】:How to get rid of BadRequestKeyError?如何摆脱 BadRequestKeyError?
【发布时间】:2020-04-18 06:59:07
【问题描述】:

我正在使用 Python 3。我已经创建了必要的文件夹。即静态和模板文件夹。尽管如此,此代码仍无法正常工作。我收到以下错误werkzeug.exceptions.BadRequestKeyError

abc.py

    from flask import Flask, request, render_template, redirect
    app=Flask(__name__)

    @app.route('/project/', methods=['GET', 'POST'])
    def tryy():
        name=request.method
        name1=request.form["uname"]
        return render_template("project1.html",name=name1)

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

project.html

    <!DOCTYPE html>

    <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <meta charset="utf-8" />
            <title></title>
        </head>
        <body>
            <form action="" method="GET">
                <input type="text" name="uname" />
                <input type="submit" value="Signup" />
            </form>
        </body>
    </html>

project1.html

    <!DOCTYPE html>

    <html>
        <head>
            <meta charset="utf-8" />
            <title></title>
            <link rel="stylesheet" type="text/css"
                  href="{{url_for('static', filename='style.css')}}" />
        </head>
        <body>
            <h1>Hey there {{name}}. Nice to meet you</h1>
        </body>
    </html>

【问题讨论】:

    标签: python-3.x flask jinja2


    【解决方案1】:

    您的表单操作设置为“” 将其更改为: &lt;form action="/project/" method="GET"&gt;

    【讨论】:

      猜你喜欢
      • 2014-01-28
      • 2013-10-31
      • 2020-10-19
      • 2019-12-01
      • 2013-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多