TypeError:contact()获得了意外的关键字参数“名称”

时间:2019-12-11 08:36:55

标签: python-3.x flask-sqlalchemy

i was creating blog website using flask and flaskALacedemy and i got error please help me for this thank you

我正在使用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)

1 个答案:

答案 0 :(得分:0)

您的函数contact不需要任何参数,而您仍然在这样做:contact(name=name,email=email,phone_no=phone,date=datetime.now(), message=message)