無法提交WTForms數據到MySQL數據庫,因爲提交的數據仍然在未綁定的字段和東西,雖然我試圖將其轉換爲字符串。不知道該怎麼辦。無法提交WTForms數據到MySQL
我正在嘗試使用Flask和WTForms創建註冊表單。我收到以下錯誤,當我去把數據(用戶名,密碼,電子郵件)到MySQL數據庫的一部分:
我已經試過到處找,但沒有在那裏,說明如何我可以解決這個問題。以下是相關代碼:
class User():
global cur
cur = config.conn.cursor()
def __init__(self, username, password, email):
self.usr = username
self.pwd = password
self.mail = email
def database(self, username, password, email):
u_p_e = cur.execute("INSERT into users (username, pwd, e-mail) VALUES ('%s', '%s', '%s')"
% (username, password, email))
cur.commit()
class Register(Form):
reg_username = TextField('Username', [validators.Length(min=1, max = 12)])
username = str(reg_username)
reg_password = PasswordField('Password', [
validators.Required(),
validators.EqualTo('confirm_password', message='Passwords do not match')
])
confirm_password = PasswordField('Confirm Password')
password = str(confirm_password)
reg_email = TextField('Email', [validators.Length(min=6, max=35)])
email = str(reg_email)
enter_db = User(username, password, email)
enter_db.database(username, password, email)
我是使用Flask/WTForms進行web開發的新手。
我對WTForms一無所知,但這不可能是正確的:你在表單定義本身,在課堂上做所有的數據庫工作。您大概需要在處理表單的處理程序中執行此操作,它將接受POST數據並進行驗證。 –