我正在用瓶子写一个小应用程序。我有一些概念上的问题可以帮助我解决它

StackOverflow https://stackoverflow.com/questions/4289115

  •  28-09-2019
  •  | 
  •  

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,以查看用户是否已验证。

其他提示

您的第二个问题已回答 这里.

您可能还想看看 烧杯的饼干会议 并使用它来保持您的应用程序的状态之间的状态。

如果我正确理解这个问题,那么渲染欢迎模板的唯一方法是通过帖子。

您可以更改此内容,以便获取请求检查是否登录某人。如果失败,请将其重定向到登录页面。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top