Issue
In my flask app , i created a function to add a new admin and show it in table. But am unable to add as it shows error that it require 1 positional argument when i input 5 arguments , but when i enter 6 arguments it gives a different error which i cannot find on internet.
>>> from web.adminMethod import *
>>> addRestadmin("id","name","mail","mobile","address","password")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "D:\projects\websites\foodWeb\web\adminMethod.py", line 23, in addRestadmin
rest=Restadmin(id,name,mail,mobile,address,password)
TypeError: __init__() takes 1 positional argument but 7 were given
>>> addRestadmin("name","mail","mobile","address","password")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: addRestadmin() missing 1 required positional argument: 'password'
>>> addRestadmin(rname=name,rmail=mail,rmobile=mobile,raddress=address,rpassword=password)
TypeError: addRestadmin() got an unexpected keyword argument 'rname'
addRestadmin() function :
def addRestadmin(id,name,mail,mobile,address,password):
rest=Restadmin(id,name,mail,mobile,address,password)
db.session.add(cust)
db.session.commit
Restadmin database structure :
class Restadmin(db.Model):
rid = db.Column(db.Integer, primary_key=True, autoincrement=True)
rname = db.Column(db.String(250), nullable=False)
rmail = db.Column(db.String(250), unique=True, nullable=False)
rmobile = db.Column(db.Integer,unique=True, nullable=False)
raddress = db.Column(db.String(250), nullable=False)
rpassword = db.Column(db.String(250), nullable=False)
Solution
addRestadmin function should look like this:
def addRestadmin(id,name,mail,mobile,address,password):
rest=Restadmin(rid=id, rname=name, rmail=mail,rmobile=mobile,raddress=address,rpassword=password)
db.session.add(rest)
db.session.commit
and call it like this:
addRestadmin("name","mail","mobile","address","password")
Answered By - softartisan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.