我已經構建了一個非常簡單的用戶登錄系統,沒有數據庫,但重定向又是一個問題。如果從HTML文件提交的用戶名&密碼是正確的,那麼蟒蛇做以下的事情:Python燒瓶用戶登錄重定向
@app.route("/", methods=['GET', 'POST'])
def login_page():
if request.method == 'POST':
attempted_username = request.form['username']
attempted_password = request.form['password']
if attempted_username == 'admin' and attempted_password == 'password':
return redirect(url_for('index'))
else:
error='E-Mail or Password not available'
return render_template('login.html', error=error)
現在的網址將成爲下一個:shost/index
和Chrome告訴我,然後
ERR_NAME_NOT_RESOLVED
The DNS address of the shost server couldnt be found.
爲什麼ISN這個URL變成了server_IP/index
,例如127.0.0.1/index
,因爲這個在我的瀏覽器中有效。我怎樣才能防止燒瓶問題shost
?
這裏也是爲登錄的HTML表單代碼:
<form class="text-left" method="post" action="">
<input class="mb0" type="text" placeholder="Username" name="username" value="{{request.form.username}}"/>
<input class="mb0" type="password" placeholder="Password" name="password" value="{{request.form.password}}"/>
<input type="submit" value="Login"/>
</form>
代碼的@app.route("/index")
部分如下所示:
@app.route("/index")
def index():
return render_template('index.html')
非常感謝和問候
請包括'login_page'和'index'路線的其餘部分。 –
@ edgaromar90感謝您的反饋。我添加了表單代碼。 – saitam
我想我知道你的問題是什麼。讓我看看你的代碼的'@ app.route(「/ index」)部分。 –