title: Django - How to use custom template tag with 'if' and 'else' checks?
body: <p>I have made a custom template tag for permissions using python:</p>
  
  <pre><code>register = template.Library()
  
  @register.simple_tag
  def get_user_perm(request, perm):
      try:
          obj = Profile.objects.get(user=request.user)
          obj_perms = obj.permission_tags.all()
          flag = False
          for p in obj_perms:
              if perm.lower() == p.codename.lower():
                  flag = True
                  return flag
          return flag
      except Exception as e:
          return ""
  </code></pre>
  
  <p>Then I loaded and used this in my template like this:</p>
  
  <pre><code>{% load usr_perm %}
  {% get_user_perm request "add_users" %}
  </code></pre>
  
  <p>Which in return prints True. Now I want to use it as a check if user has permission or not?  How can I use this template tag with <code>if</code> and <code>else</code> conditions?
  Currently I am using it like this:</p>
  
  <pre><code>{% if get_user_perm request "add_users" %}Can Add User{% else %} Permission Denied {% endif %}
  </code></pre>
  
  <p>Is there any way that I can tweak in template tag's code or any hint to use template tag in template.<br>
  N.B: Previously I was using Django's permissions like this <code>{% if perms.profile.add_user %}</code> but due to some reasons I have to write my own template tag now!<br>
  Any help will be greatly appreciated! Thanks</p>