0

Is there a way to access the flask principal in order to execute some code conditionally?

In a functiod, I'd like to do something like:

def load_some_stuff():

  if <user is an admin>:
      load_report_data()
  #more code, render template etc...

then in the template:

{% if report_data %}
   // report rendering code goes here
{% endif %}
fansonly
  • 1,150
  • 4
  • 14
  • 29

1 Answers1

0

You're looking for Flask-Principal's context manager usage:

admin_permission = Permission(RoleNeed('admin'))

with not admin_permission.require():
    do_something()
atx
  • 4,831
  • 3
  • 26
  • 40