Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google App Engine Python If Else Usage in Html Template

I am creating a web site in google app engine using python. Unfortunately, I could not find anything concerning my problem. I have to distinguish a variable according to its content.

For example i am going to send variables like this

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

And i need such kind of code to understand the type of user if it is a 'Login' user or 'Admin' user.

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

How can i do this?

Or maybe there is better design that you can suggest me.

Thank you...

like image 387
gurkan Avatar asked Jan 20 '23 15:01

gurkan


1 Answers

There is no elif in django templates. 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 %}
like image 97
Gabi Purcaru Avatar answered Jan 30 '23 19:01

Gabi Purcaru