in

Getting error after adding db to flask app


Problem is after clicking submit button it is giving error

from flask import Flask , render_template, request, jsonify
from flask_sqlalchemy import SQLAlchemy
import datetime as dt
from flask_marshmallow import Marshmallow

#app config
app=Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI']="sqlite:///site.db"

#db
db=SQLAlchemy(app)
ma=Marshmallow(app)

#model
class contact(db.Model):
    id= db.Column(db.Integer, primary_key="True")
    name= db.Column(db.String(30), nullable=False)
    mobile= db.Column(db.Integer, unique=True, nullable=False)
    email= db.Column(db.String(45), nullable=False)
    company_name= db.Column(db.String(30), nullable=False)
    subject= db.Column(db.String(45), nullable=False)
    message= db.Column(db.Text, nullable=False)
    date_posted= db.Column(db.DateTime, nullable=False, default=dt.datetime.now())

class ContactSchema(ma.Schema):
    class Meta:
        fields=("id","name","mobile","email","company_name","subject","message","date_posted")

cnt_schema= ContactSchema()
cnts_schema= ContactSchema(many=True)

#pages
@app.route("/", methods=['GET', 'POST'])
def index():
    if request.method == "POST":
        name= request.form.get("Name")
        mobile= request.form.get("mobile")
        email= request.form.get("email")
        cmp_nm= request.form.get("c_name")
        sub= request.form.get("subject")
        msg= request.form.get("msg")
        
        #storing into db
        cnt= contact(name,mobile,email,cmp_nm,sub,msg)
        db.session.add(cnt)
        db.session.commit()
        #alter box required
    return render_template("index.html")

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

after visiting the app on the contact section user can fill his details then submit but after submitting this app giving error.

  • this code generating following error*

TypeError

TypeError: init() takes 1 positional argument but 7 were given



Source: https://stackoverflow.com/questions/70631216/getting-error-after-adding-db-to-flask-app

Better API for React — without JSX

HostMatch V 1.0 — Like Tinder for podcast hosts