【发布时间】:2026-01-31 23:50:02
【问题描述】:
您好,我是一名新程序员,我刚开始使用烧瓶制作网站,在我最近的项目中,我遇到了数据库问题(错误名称是标题;))这是我的代码(我正在制作迷你优酷)
@app.route("/create_acc", methods=["POST", "GET"])
def create_acc():
if request.method == "POST":
name = request.form["nm"]
check = ChannelDB.query.filter_by(name=name).first()
if not check:
email = request.form["em"]
psw = request.form["ps"]
channel = ChannelDB(name, email, psw, 0, 0)
db.session.add(channel)
db.session.commit()
return redirect(url_for("user"))
else:
abort(409, message="Video alredy exists")
这是产生错误的地方。
class ChannelDB(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(100), nullable=False)
email = db.Column(db.String(100), nullable=False)
password = db.Column(db.String(100), nullable=False)
subs = db.Column(db.Integer, nullable=False)
num_of_videos = db.Column(db.Integer, nullable=False)
这是我的数据库。
{% extends "base.html" %}
{% block title %}Login Page{% endblock %}
{% block content %}
<form action="/create_acc", method="post">
<p>Name: </p>
<p><input type="text" name="nm"></p>
<p>Email: </p>
<p><input type="text" name="em"></p>
<p>Password: </p>
<p><input type="text" name="ps"></p>
<p>Press this button when you fill the spots above</p>
<p><input type="submit" value="submit"></p>
</form>
{% end block %}
这是我的登录名。 html文件
【问题讨论】: