我正在学习cs50教程04,从中我得到了以下错误
错误:-“DefaultMeta”对象不可编辑, 请检查我的代码我认为问题是从如果开始的声明,但我无法解决问题,请帮助
from flask import Flask, render_template, request
from models import *
app = Flask(__name__)
app.config["SQLALCHEMY_DATABASE_URI"] = "postgresql://postgres:password@localhost:5432/postgres"
app.config["SQLALCHEMY_TRACK_MODIFIER_MODIFICATIONS"] = False
db.init_app(app)
@app.route("/")
def indexapp():
railway = Railway.query.all()
return render_template("indexapp.html", Railway=Railway)
@app.route("/book", methods=["POST"])
def book():
""" BOOK A Railway """
#Get Form Information
name = request.form.get("name")
try:
railway_id = int(request.form.get("railway_id"))
except ValueError:
return render_template("error.html", message="Invalid Railway Number.")
#Make Sure the Railway Exists
railway = Railway.query.get(flight_id)
if railway is None:
return render_template("error.html", message="No Such Railway with this id.")
#ADD Passenger
passenger = Passenger(name=name, railway_id=railway_id)
db.session.add(passenger)
db.session.commit()
return render_template("sucess.html")
你不申报吗
。如果它来自模型,则用逗号将其括起来
试试这个
相关问题 更多 >
编程相关推荐