烧瓶,Python 3,错误:“;其他参数应命名为“引用”;

烧瓶,Python 3,错误:“;其他参数应命名为“引用”;,python,flask,sqlalchemy,Python,Flask,Sqlalchemy,问题: 我得到了一个errorusig flask,我正在遵循一个教程(使用flash,我是一个meh级别的python程序员(我掌握了基本知识)),所以我不明白为什么或者这有什么错,所以如果你不介意解释它或者添加一个链接到一个地方,它被解释了。。。错误(对不起,我不知道什么是重要的): 现在,我不知道您还需要什么,与此相关的其他文件称为: forms.py about.html home.html layout.html login.html

问题: 我得到了一个errorusig flask,我正在遵循一个教程(使用flash,我是一个meh级别的python程序员(我掌握了基本知识)),所以我不明白为什么或者这有什么错,所以如果你不介意解释它或者添加一个链接到一个地方,它被解释了。。。错误(对不起,我不知道什么是重要的):

现在,我不知道您还需要什么,与此相关的其他文件称为:

    forms.py

    about.html

    home.html

    layout.html

    login.html

    register.html

    main.css

我没有添加它们,因为如果没有,我会添加太多的代码,但是如果您需要什么,只需回答:D

看起来您在
Post
类的
user\u id
字段中输入了一个错误

你写道:

user\u id=db.Column(db.Integer,db.ForeignKey(“user.id”,nullable=False))
正确的时间是:

user\u id=db.Column(db.Integer,db.ForeignKey(“user.id”),nullable=False)

您的命名约定或语法有错误


在我的例子中,当引用子类中的外键时,我的类名todolists(Parent)中缺少
s

在我的例子中,
nullable=False

我写了nunlable=False


解决后,修复了打字错误nullable=False

谢谢你,先生是一个传奇,你是这个网站的活美人,我一定会帮助别人解决我能解决的问题,谢谢你,你让我免于放弃!!不客气。我很高兴在我来这里的第一天读到这篇文章。这是一个很好的机会让你开始做同样的事(谢谢你的回答,我也犯了同样的错误。
from flask import Flask, escape, request, render_template, url_for, flash, redirect
from flask_sqlalchemy import SQLAlchemy
from forms import RegistrationForm, LoginForm
from datetime import datetime

app = Flask(__name__)
app.config["SECRET_KEY"] = "16ee14ac45b13e16aca29d7827e58366"
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///site.db"
db = SQLAlchemy(app)

class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(20), unique = True, nullable=False)
    email = db.Column(db.String(120), unique = True, nullable=False)
    image_file = db.Column(db.String(20), nullable=False, default="default.jpg")
    password = db.Column(db.String(60), nullable=False)
    posts = db.relationship("Post", backref="auther", lazy=True)

    def __repr__(self):
        return f"User('{self.username}', '{self.email}', {self.image_file})"

class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)
    date_posted = db.Column(db.DateTime, nullable=False, default = datetime.utcnow)
    content = db.Column(db.Text, nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey("user.id", nullable=False))

    def __repr__(self):
        return f"Post('{self.title}', '{self.date_posted}')"

posts = [
{
    "auther": "ed",
    "title": "blog 1",
    "content": "first post",
    "sate_posted": "1/1/79"
},
{
    "auther": " not ed",
    "title": "blog 2",
    "content": "second post",
    "sate_posted": "2/1/79"
}]

@app.route('/')
@app.route('/home')
def home():
    return render_template("home.html", posts=posts)

@app.route('/about')
def about():
    return render_template("about.html", title = "about")

@app.route('/register', methods=["GET", "POST"])
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        flash(f"Account created for {form.username.data}!", "success")
        return redirect(url_for("home"))
    return render_template("register.html", title = "Register", form = form)

@app.route('/login', methods=["GET", "POST"])
def login():
    form = LoginForm()
    if form.validate_on_submit():
        if form.email.data == "admin@blog.com" and form.password.data == "password":
            flash("You have been logged in!", "success")
            return redirect(url_for("home"))
        else:
            flash("Login Unsuccesful. please check username and password", "danger")
    return render_template("login.html", title = "Login", form = form)


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

    forms.py

    about.html

    home.html

    layout.html

    login.html

    register.html

    main.css