Error: "typeerror: Hidden_tag() Missing 1 Required Positional Argument: 'self' " In Flask, Python
Solution 1:
The TypeError is saying that self was not passed to the hidden_tag method. You can have this error if you do the following by accident:
classA:
deftest(self):
print('test')
A.test() # TypeError: test() missing 1 required positional argument: 'self'
A().test() # prints test
So this means that you are calling the method with a class object.
In your routes, you have the following rule where you pass a class to your page, but you likely wanted to return your actual form object. So you have to change
return render_template('addUser.html', title='Admin', form=AddUserForm)
to
form = AddUserForm('/login')
...
return render_template('addUser.html', title='Admin', form=form)
Solution 2:
You forgot to call the form at the end of your last return statement.
current code
else:
flash('Account not created')
return render_template('addUser.html', title='Admin', form=AddUserForm)
fixed code
else:
flash('Account not created')
return render_template('addUser.html', title='Admin', form=AddUserForm())
or since you already specified that
form = AddUserForm('/login')
just specify it at the end like you did in other routes
return render_template('addUser.html', title='Admin', form=form)
Solution 3:
Well, me following the same tutorial from Corey Schafer's flask. The main reason why you are getting TypeError: hidden_tag() missing 1 required positional argument: 'self
is because of the route page form the bracket needs to prevent the error and to signify the tag function()
Post a Comment for "Error: "typeerror: Hidden_tag() Missing 1 Required Positional Argument: 'self' " In Flask, Python"