发布于 2015-12-11 21:27:56 | 630 次阅读 | 评论: 1 | 来源: PHPERZ

这里有新鲜出炉的Explore Flask中文版,程序狗速度看过来!

Flask 轻量级Python Web开发框架

Flask是一个使用Python编写的轻量级Web应用框架。基于Werkzeug WSGI工具箱和Jinja2 模板引擎。使用 BSD 授权。


错误描述

@auth_blueprint.before_app_request
def before_request():
    if current_user.is_authenticated :
        pass
    elif request.path != '/auth/login':
        return redirect(url_for('auth.login'))

当我添加上述代码时,我发现
http://www.test.so/auth/login的第一行报错,查看后没发现问题。上stackoverflow上有人说是错误的把html当做js解析,例如ajax返回值指定出错

错误排查

后来我在return之前加了一句打印,发现其实不止html文件被重定向了,所有的静态文件都被重定向到http://www.test.so/auth/login,然后,在原html中,他们被指定为js,css,所以解析自然会报错,将代码做了一下调整,解决问题

@auth_blueprint.before_app_request
def before_request():
    if current_user.is_authenticated :
        pass
    elif request.path != '/auth/login' and not re.match('/static/', request.path):
        return redirect(url_for('auth.login'))


最新网友评论  共有(1)条评论 发布评论 返回顶部
hgb 发布于2016-09-11 20:46:56
完美,感谢分享
支持(0)  反对(0)  回复

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务