我正在用瓶子写一个小应用程序。我有一些概念上的问题可以帮助我解决它
题
from bottle import route, run, debug, error, request, template
@route('/home')
@route('/home/')
def login():
return template('templates/login')
@route('/home', method='POST')
@route('/home/', method='POST')
def welocme():
data = request.POST
if data:
password = data.get('password')
check_pass = 'password'
if password == check_pass:
return template('templates/welcome')
else:
return template('templates/login')
else:
return template('templates/login')
我的要求是:我将在同一URL上获得登录和欢迎页面。登录页面只有一个密码字段。
我的问题:如果我获得登录并在刷新时再次访问欢迎页面,它会将我发送到登录页面。但理想情况下,它应该仅在欢迎页面上。
@error(404)
def error404(error):
return 'http://google.com'
我的第二个问题是:我想在404上重定向特定的URL。
解决方案
如果用户转到“/home”页面,您是否不想检查他们是否在显示登录屏幕之前登录?就像您认为如果没有发布HTTP方法,您似乎尚未登录。
我对您的框架了解不多,但是我假设如果登录成功,您应该设置一个cookie,然后您应该检查cookie for http,以查看用户是否已验证。
不隶属于 StackOverflow