Reputation: 11
I have this signup page and when i am submitting the form i am getting this error:not all arguments converted during string formatting
class RegistrationForm(Form):
email = StringField('Email address')
password = PasswordField('password')
name = StringField('Name')
@app.route('/register/', methods=['GET', 'POST'])
def register():
try:
form = RegistrationForm(request.form)
if request.method == 'POST':
email = form.email.data
password = sha256_crypt.encrypt((str(form.password.data)))
con = connection()
cur=con.cursor()
x = cur.execute("SELECT * FROM user WHERE username = (%s)",(thwart(email)))
if int(x) > 0:
return render_template('register.html',form=form)
else:
cur.execute("INSERT INTO user (username,password,name) VALUES (%s,%s,%s);",(thwart(email),thwart(password),thwart(name),))
con.commit()
cur.close()
con.close()
return redirect(url_for('dashboard'))
return render_template('register.html', form=form)
except Exception as e:
return str(e)
Upvotes: 1
Views: 897
Reputation: 81684
x = cur.execute("SELECT * FROM user WHERE username = (%s)",(thwart(email)))
The second argument of execute
should be a tuple, you are missing a ,
:
cur.execute("SELECT * FROM user WHERE username = (%s)",(thwart(email),))
I guess that you also don't need the ()
around the %s
but it depends on how your table actually looks like.
Further clarification:
('str')
will evaluate to the string 'str'
, not to a tuple containing it.
In order to create a one-tuple, you must include a comma: ('str',)
.
Upvotes: 1