python-3.x - 如何摆脱 BadRequestKeyError?
问题描述
我正在使用 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)
项目.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>
项目1.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>
解决方案
您的表单操作设置为“”,将其更改为:
<form action="/project/" method="GET">
推荐阅读
- javascript - 我在使用 React 路由器时遇到问题,因为我的 url 在点击它时会得到更新,但页面没有被呈现
- r - R中的SOAP请求,带有WS-security,SOAPHandler
- sql - 我有一个查询,将输出作为开始日期和结束日期之间的年份和月份
- apache-camel - Camel Azure 存储 Blob 使用者未按预期工作(Blob 持续消耗)
- python - 命名实体识别模型总是预测相同的类别,但准确率达到 99%
- c++ - 从 kv 存储缓存元数据的最佳方法
- python - Python Selenium,即使元素是可交互的,输入字段也会返回 ElementNotInteractableException
- c# - Multilingual App Toolkit 是否与多目标框架兼容?
- c# - 当我尝试在单个文本框中显示数据库中的 3 条记录时,仅显示最后一条记录,而不是 asp.net 空框架中的前两条
- android - 如何在 koltin android 中使用 volley 获取 json