librelist archives

« back to archive

Access module variables in a template

Access module variables in a template

From:
Malphas Wats
Date:
2012-07-17 @ 08:38
Hi,

  This is probably really obvious, but I haven't worked it out yet.

I have an access_control.py module in my project, it defines some
access level constants at the top.

I'd like to be able to show/hide various controls in my templates
based on the values of the logged in account, but I can't do this:

    {% if session['user']['account_type'] > access_control.STUDENT_ACCOUNT %}

so for now I've just been hard-coding the values in, which feels dirty.

Is there any way to make these available to the template? Is the only
way to pass flags in every time I want to render it?

Thanks

-Mike

Re: [flask] Access module variables in a template

From:
Simon Sapin
Date:
2012-07-17 @ 09:03
Le 17/07/2012 10:38, Malphas Wats a écrit :
>      {% if session['user']['account_type'] > access_control.STUDENT_ACCOUNT %}
>
> so for now I've just been hard-coding the values in, which feels dirty.
>
> Is there any way to make these available to the template? Is the only
> way to pass flags in every time I want to render it?

Hi,

Try this in your Python code:

import access_control
app.jinja_env.globals['access_control'] = access_control

-- 
Simon Sapin