ThomasD
ThomasD

Reputation: 2494

combining if and ifequal in django

I have two variables: isAdmin (a boolean) username (a string)

I need to evaluate whether the is an administrator OR the username equals a certain username. I tried

{% if isAdmin or ifequal username 'xyz' %}

but I cannot get it to work.

So how do I combine a check on these two variables ?

thanks Thomas

Upvotes: 2

Views: 169

Answers (2)

Anish Shah
Anish Shah

Reputation: 8169

You can calculate in your views function and pass it into the template

Here's a rough snippet

def view_function(request):
      #your code
      if isAdmin or username == 'xyz':
           arg = true
      return render_to_response('template.html', {'arg': arg})

In your template

{% if arg %}

Upvotes: 0

Selcuk
Selcuk

Reputation: 59184

You can not combine ifequal with if but you can also write

{% if isAdmin or username == 'xyz' %}

Upvotes: 2

Related Questions