1
如何使POST方法適用於燒瓶在同一頁上的兩種不同形式?如何使POST方法適用於燒瓶在同一頁上的兩種不同形式?
下面是主要__int__.py
文件瓶/蟒蛇我的代碼
@app.route('/', methods=['GET', 'POST'])
@app.route('/login/', methods=['GET', 'POST'])
def login():
error = None
if request.method == 'POST':
if request.form['email'] != '1' or \
request.form['password'] != '1':
flash('Invalid Credentials')
else:
flash('You were successfully logged in')
return redirect(url_for('dashborad'))
return render_template('login.html', error=error)
@app.route('/', methods=['GET', 'POST'])
@app.route('/register/', methods=['GET', 'POST'])
def register():
try:
if request.method == 'POST':
email = request.form['email1']
name = request.form['name1']
password = request.form['password1']
cur, db = connection()
x = cur.execute(" SELECT * FROM users WHERE email = (%s)" ,[escape(email)])
if int(x) > 0:
flash ("email already used ")
return render_template ("register.html")
else:
cur.execute("INSERT INTO users (first_name, email, password) VALUES (%s, %s, %s);" ,(escape(name), escape(email), escape(password)))
db.commit()
return render_template ("register.html")
現在蟒蛇正在讀POST方法首先@ app.route登錄表單只
有沒有簡單的方法來獲得這樣的在python中的行?
if request.method == 'POST' for form 1
和
if request.method == 'POST' for form 2
感謝您的回答,但它給了這個錯誤 400錯誤請求:瀏覽器(或代理)發送的請求該服務器無法理解。 –
[使用此](https://stackoverflow.com/questions/21949452/wtforms-two-forms-on-the-same-page) – vutsuak
我想我必須使用WTForms畢竟 我有一個項目使用作爲儘可能少的框架 再次感謝好友 –