推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
RealLiuSha
V2EX  ›  Python

关于 flask 认证的小疑惑

  •  
  •   RealLiuSha · Feb 15, 2016 · 3582 views
    This topic created in 3882 days ago, the information mentioned may be changed or developed.

    @app.route('/secret-page')
    @requires_auth
    def secret_page():
    return render_template('secret_page.html')

    借用了一下官方的 example , 如果我有 N 个方法都需要认证,是所有的方法都需要加上 @requires_auth 嘛,望有经验的童鞋给予指导,感谢哦

    zjnjxufe
        1
    zjnjxufe  
       Feb 15, 2016
    如果全部都要认证,那可以不用写在每个 endpoint 前。 否则的话好像只能一个个加了..
    jixiangqd
        2
    jixiangqd  
       Feb 15, 2016
    有 before_request ,可以判断请求 url 自己写逻辑来自定义黑白名单做权限验证
    RealLiuSha
        3
    RealLiuSha  
    OP
       Feb 15, 2016
    @jixiangqd @zjnjxufe 好的哈, 我试一下, before_request 这个我倒是没想到, 感谢了。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2329 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 08:45 · PVG 16:45 · LAX 01:45 · JFK 04:45
    ♥ Do have faith in what you're doing.