Cookies 使用Flask应用程序删除登录表单中的会话cookie
我正在开发一个简单的烧瓶应用程序,它有两个部分;第一部分是登录表单(Cookies 使用Flask应用程序删除登录表单中的会话cookie,cookies,flask,Cookies,Flask,我正在开发一个简单的烧瓶应用程序,它有两个部分;第一部分是登录表单(Login.html),其中用户必须填写一些ID号。当按下Submit按钮时,ID号存储到cookie中,并呈现第二页(index.html) 我观察到了不希望出现的行为:当我重新加载第二个页面时,正确呈现了带有登录表单的第一个页面(并且删除了cookie)。但是,如果我再次按下“重新加载”按钮,第二页将加载cookie 对于如何删除此设置中的cookie,我很乐意提供任何建议 烧瓶文件如下所示: from flask impo
Login.html
),其中用户必须填写一些ID号。当按下Submit按钮时,ID号存储到cookie中,并呈现第二页(index.html
)
我观察到了不希望出现的行为:当我重新加载第二个页面时,正确呈现了带有登录表单的第一个页面(并且删除了cookie)。但是,如果我再次按下“重新加载”按钮,第二页将加载cookie
对于如何删除此设置中的cookie,我很乐意提供任何建议
烧瓶文件如下所示:
from flask import Flask, request, render_template, session, redirect, url_for
app = Flask(__name__)
app.secret_key = 'abc'
@app.route('/', methods=['GET', 'POST'])
def login():
if request.method == 'POST':
if session.get('logged_in') is None:
session['id_number'] = request.form['id_number']
session['logged_in'] = True
return render_template('index.html')
return render_template('login.html')
@app.route('/logout')
def logout():
session.clear()
return redirect(url_for('login'))
if __name__ == '__main__':
app.run(debug=True, port=5000)
下面是login.html
文件的主要部分:
<script type="text/javascript">
window.onload = function (e) {
$.ajax({
type: 'GET',
async: false,
url: '/logout',
data: { IsRefresh: 'Close' }
});
};
</script>
<form action="{{ url_for('login')}}" method="post">
<input type="text" name="id_number" id="id_number">
<input type="submit" name="submit" value="Enter">
</form>
window.onload=函数(e){
$.ajax({
键入:“GET”,
async:false,
url:“/logout”,
数据:{IsRefresh:'Close'}
});
};
我认为您必须使用返回重定向(url\u for('index',var=var))
来代替返回
render_template('index.html')
,此外,您必须检查这一点,呈现模板和使用重定向功能之间存在差异。我认为您必须使用返回重定向(url_for('index',var=var))
代替返回
render_template('index.html')
,此外,您必须检查这一点,呈现模板和使用重定向功能之间存在差异