我正在使用flask和flaskALacedemy创建博客网站,但出现错误,请为此提供帮助
from flask import Flask,render_template,request
from flask_sqlalchemy import SQLAlchemy
from datetime import datetime
app=Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] =
'mysql://root:@localhost/myfirstweb'
db = SQLAlchemy(app)
class Contact(db.Model):
serial_no = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(20), unique=False, nullable=False)
email = db.Column(db.String(20), unique=False, nullable=False)
phone_no = db.Column(db.String(12), unique=False, nullable=False)
message = db.Column(db.String(120), unique=False, nullable=False)
date = db.Column(db.String(12), unique=False, nullable=True)
@app.route('/')
def home():
return render_template('index.html')
@app.route('/about')
def about():
return render_template('about.html')
@app.route('/contact', methods = ['GET', 'POST'])
def contact():
if(request.method=='POST'):
name = request.form.get('name')
email = request.form.get('email')
phone = request.form.get('phone')
message = request.form.get('message')
entry =
contact(name=name,email=email,phone_no=phone,date=datetime.now(),
message=message)
db.session.add(entry)
db.session.commit()
return render_template('contact.html')
@app.route('/post')
def post():
return render_template('post.html')
app.run(debug=True)
答案 0 :(得分:0)
您的函数contact
不需要任何参数,而您仍然在这样做:contact(name=name,email=email,phone_no=phone,date=datetime.now(), message=message)