29👍
✅
article.creator
is a User
and request.user.username
is a string. Try comparing request.user
instead.
80👍
For string compare in template use
{% if name == "someone" %}
............
............
{% endif %}
and for not equal
{% if name != "someone" %}
............
............
{% endif %}
- [Django]-Add additional options to Django form select widget
- [Django]-How to get getting base_url in django template
- [Django]-How to get form fields' id in Django
69👍
Try this:
{% ifnotequal article.creator|stringformat:"s" request.user.username %}
- [Django]-Homepage login form Django
- [Django]-Stack trace from manage.py runserver not appearing
- [Django]-Django: How to get related objects of a queryset?
- [Django]-What is the difference between {% load staticfiles %} and {% load static %}
- [Django]-Django Celery Logging Best Practice
- [Django]-Django rest framework, use different serializers in the same ModelViewSet
1👍
Note that if you do not put spaces before and after ==, Django could not parse the expression.
{% if MyProd.Status == "Processing" %}
<button class="btn btn-outline-warning">{{MyProd.Status}}</button>
{% else %}
<button class="btn btn-outline-success">{{MyProd.Status}}</button>
{% endif %}
- [Django]-How to query abstract-class-based objects in Django?
- [Django]-Django, query filtering from model method
- [Django]-Django Rest Framework Conditional Field on Serializer
Source:stackexchange.com