Hiding inaccessible links in Jinja2 templates

后端 未结 2 520
我在风中等你
我在风中等你 2021-02-04 16:20

We\'re writing a web application in Flask + Jinja2 at work. The application has registered users which can access certain pages based on their roles. In order to achieve this o

2条回答
  •  孤独总比滥情好
    2021-02-04 16:49

    I use Flask-Security, which ties a lot of the login/security modules together in a nice package. It comes with role management courtesy of Flask-Principal, which will allow you to do:

    {% if current_user.has_role('admin') %}
        
  • Manage Site
  • {% endif %}

    You can see how that's implemented in the source, the current_user proxy comes from Flask-Login

提交回复
热议问题