2
嘗試爲我的應用程序創建一個註冊頁面。我使用的Flask框架和MySQL db從pythonanywhere.com。燒瓶,並非在字符串格式化過程中轉換的所有參數
@app.route('/register/', methods=["GET","POST"])
def register_page():
try:
form = RegistrationForm(request.form)
if request.method == "POST" and form.validate():
email = form.email.data
password = sha256_crypt.encrypt((str(form.password.data)))
c, conn = connection()
x = c.execute("SELECT * FROM users WHERE email = (%s)",
(email))
if int(x) > 0:
flash("That email adress is already in use.")
return render_template('register.html', form=form)
else:
c.execute("INSERT INTO users (email, password) VALUES (%s, %s)",
(thwart(email),thwart(password)))
conn.commit()
flash("Thanks for registering!")
c.close()
conn.close()
gc.collect()
session['logged_in'] = True
session['email'] = email
return redirect(url_for('dashboard'))
return render_template("sign-up.html", form=form)
except Exception as e:
return(str(e))}
運行時出現錯誤:並非所有在字符串格式化過程中轉換的參數。 如何解決它?可能是這個聲明中的問題?
c.execute("INSERT INTO users (email, password) VALUES (%s, %s)", (thwart(email),thwart(password)))
我正在使用MySQL – Vasile
您是否100%確定錯誤在該行發生?我認爲這個問題更可能出現在上面的x = c.execute()行,你應該把'(email)'' - 注意尾部的逗號 - 作爲最後一個參數,而不是'(email)'沒有尾隨逗號。 –
我將'(email)'改爲'(email,)'並得到了相同的結果 – Vasile