简体   繁体   中英

Show flask security roles in jinja2

I've created roles and assigned the to users. I can show the current logged in users name with {{current_user}} in jinja2. How do I show a users role(s) in jinja2?

For example: Hi {{current_user}}, you have the roles: {{roles}}

You need to pass those values as kargs in the render_template.

from flask import render_template
from flask_login import current_user

@app.route("/roles")    
def my_route():
    return render_template("roles.html", current_user=current_user, roles=current_user.roles)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM