5

I have this code of line that I need to be up and running.

<h4 class="page-header">
    {% if msg.sent_by_id == request.user.public_id|string %}
        {% if request.user.role == 'administrator' %}Admin Replied
        {% elif request.user.role == 'user' %}Your reply
        {% endif %}
    {% endif %}
</h4>

The problem is that these two values are the same, BUT both of them are other format. msg.sent_by_id is a string, neither request.user.public_id, this value is in uuid format. What is the correct way of 'converting' an variable to a string and then comparing the two values?

2
  • str (uuid) in your view and pass the str version into your template Commented Jul 30, 2020 at 22:07
  • I'm passing the whole json object -return render(request, 'service_desk/ticket_status.html', {'ticket': Ticket_obj, 'ticket_messages': Ticket_obj_messages}) Commented Jul 30, 2020 at 22:12

1 Answer 1

11

You could use the string format template tag https://docs.djangoproject.com/en/3.0/ref/templates/builtins/#stringformat

{% if msg.sent_by_id == request.user.public_id|stringformat:"s" %}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.