Python Django:在Django模板引擎中将uuid值转换为字符串
我有这行代码,我需要启动和运行Python Django:在Django模板引擎中将uuid值转换为字符串,python,html,django,jinja2,Python,Html,Django,Jinja2,我有这行代码,我需要启动和运行 <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
<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>
{%if msg.sent_by_id==request.user.public_id | string%}
{%if request.user.role=='管理员'%}管理员已回复
{%elif request.user.role==“用户”}您的答复
{%endif%}
{%endif%}
问题是这两个值是相同的,但它们都是其他格式
msg.sent\u by\u id
是字符串,也不是request.user.public\u id
,此值采用uuid
格式。将变量“转换”为字符串,然后比较这两个值的正确方法是什么?您可以使用字符串格式模板标记
str(uuid)
在您的视图中,将str版本传递到您的模板我正在传递整个json对象-返回呈现(请求'service\u desk/ticket\u status.html',{'ticket':ticket\u obj,'ticket\u messages':ticket\u obj\u messages})
{% if msg.sent_by_id == request.user.public_id|stringformat:"s" %}