Google App Engine Python, if used in an HTML template

I am building a website in google engine using python. Unfortunately, I could not find anything regarding my problem. I have to distinguish a variable according to its content.

For example, I'm going to send such variables

content = {
       'mail':session.get('user_mail',''),
       'role':'Admin',
       }
render_template(self, 'index.html', content)

And I need such a code in order to understand the type of user if he is the user "Login" or "Administrator".

{% if role == 'Ordinary' %}
    {{ role }}
{% elif role == 'Admin' %}
    {{ role }}
{% endif %}

How can i do this?

Or maybe there is the best design you can offer me.

Thank...

+3
source share
2 answers

There is no django templates elif. Use something like this:

{% if role == 'Login' %}
 ... stuff
{% else %}{% if role eq 'Admin' %}
 ... stuff
{% endif %}

Or, with ifequal:

{% ifequal role "Login" %}
 ... stuff
{% else %}{% ifequal role "Admin" %}
 ... stuff
{% endifequal %}
+6
source

:

content = {
   'mail':session.get('user_mail',''),
   'role':'Admin',
   'show_role':True,
   }

content = {
   'mail':session.get('user_mail',''),
   'role':'YetAnther',
   'show_role':False,
   }

{% if show_role %}{{role}}{% endif %}
+3

Source: https://habr.com/ru/post/1788932/


All Articles