Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django - use template tags in if statement [duplicate]

Tags:

I saw similar questions but none of them solved my problem .

I have a simple template tag like this :

@register.simple_tag
def liked_by_user(post_id, user):
    try:
        PostModel.objects.get(pk=post_id).like_set.get(user=user)
        return True
    except:
        return False

and i want to use this in an if statement like this :

{% if liked_by_user post.pk request.user %}
        doing somethin...
    {% else %}
        doing somethin...
{% endif %}

what can i do ?