python - 为什么我在 Python 中收到 BadRequestKeyError?
问题描述
当我尝试在 python 中运行以下代码时出现此错误。
我的 signup.html 代码:
<html>
<head>
<title>Signup</title>
<link href="../static/styles/bookreview.css" rel="stylesheet"
type="text/css">
</head>
<body>
<!--Specifying navigation bar-->
<nav>
<img id="logo" src="../static/images/OUAT Logo.png" alt="Once Upon A Time Logo">
<ul>
<li><a href="/">Home</a></li>
<li><a href="Review Books">Books</a></li>
<li><a href="Guestbook">Guestbook</a></li>
<li><a href="Contact Us">Contact</a></li>
</ul>
<img id="searchicon" src="../static/images/Search Icon.png">
<form>
<input id=searchbar type=text>
</form>
<a href="Login"><button id=navsignin>Sign in</button></a>
</nav>
<div class="containers signupcontainer">
<img id=signupgraphic src="../static/images/signupgraphic.png">
<h2>Create an account and start <font color="#FF6572">commenting!</font>
</h2>
<!--{{msg}}-->
<form action="" method="POST">
<label>Full Name</label>
<input class=signupfields type="text">
<label>E-mail address</label>
<input class=signupfields type="text">
<label>Enter new password</label>
<input class=signupfields type="password">
<label>Re-enter password</label>
<input class=signupfields type="password">
<button class="buttons signupbutton">Create account</button>
</form>
</div>
</body>
</html>
我的python代码:
from flask import Flask, redirect, request, url_for, render_template
app = Flask(__name__, static_folder='static')
import sqlite3 as s
DB_FILE = 'mydb'
connection = s.connect(DB_FILE, check_same_thread=False)
@app.route('/')
def index():
return render_template('Index.html')
@app.route('/Review Books')
def review():
return render_template('Review.html')
@app.route('/Guestbook')
def guestbook():
return render_template('Guestbook.html')
@app.route('/Contact Us')
def contact():
return render_template('Contact.html')
@app.route('/Login')
def login():
return render_template('Login.html')
def _insertuser(name, email, password, repeatpass):
params = {'name': name, 'email': email, 'password': password,
'repeatpass': repeatpass}
cursor = connection.cursor()
cursor.execute("insert into users(name, email, password, repeatpass)
values (:name, :email, :password, :repeatpass)", params)
connection.commit()
@app.route('/Signup', methods=['POST', 'GET'])
def signup():
if request.method == 'POST':
_insertuser(request.form['name'], request.form['email'],
request.form['password'], request.form['repeatpass'])
return render_template('Signup.html', msg=" thank you for signing
up")
else:
return render_template('Signup.html')
if __name__ == '__main__':
app.run(debug=True)
我已经看到了类似的问题,并且我一直在进行更正,但我仍然收到此错误。有人可以帮我理解为什么我会收到这个错误,以及我是否遗漏了什么。
谢谢你的时间。
解决方案
它缺少name
属性<input>
<form action="" method="POST">
<label>Full Name</label>
<input name="name" class=signupfields type="text">
<label>E-mail address</label>
<input name="email" class=signupfields type="text">
<label>Enter new password</label>
<input name="password" class=signupfields type="password">
<label>Re-enter password</label>
<input name="repeatpass" class=signupfields type="password">
<button class="buttons signupbutton">Create account</button>
</form>
推荐阅读
- reactjs - mockRejectedValueOnce 不是函数
- vim - 将运行 neovim 的终端标题更改为 appimage
- java - 接口 io.javabrains.repository.DepartmentRepository 的问题
- gitversion - 如何通过 GitVersion 禁用使用分支名称
- machine-learning - BERT 中的 TokenEmbeddings 是如何创建的?
- python-3.x - 如何防止字节 b'\x3f' 变成 b'?在 Python 3 中打印时
- c# - 在 jetbrains 骑手中找不到 aspx.cs
- winapi - 在 ScrollWindow() 之后更新窗口。WinAPI
- servicestack - ServiceStack 中的补丁
- java - Jersey Exception Mapper 关于异常原因