我的模板循环中有一个条件,如下所示:
{% for message in message_trash %}
<td><a href="#">
{% if request.session.user_email == message.message_user_reciever.user_email %}
{{ message.message_user_reciever.user_firstName }} {{ message.message_user_reciever.user_lastName }}
{% elif request.session.user_email == message.message_user_sender.user_email %}
{{ message.message_user_sender.user_firstName }} {{ message.message_user_sender.user_lastName }}
{% endif %}
</a><small><a href="#">Friends</a></small></td>
{% endfor %}
但我不知道为什么我在应用网址时会出现此错误?
TemplateSyntaxError: Could not parse the remainder: '==message.message_user_reciever.user_email' from 'request.session.user_email==message.message_user_reciever.user_email'
这是我呈现给模板的视图和变量:
def trashMessages(request, userId):
if isMessageOwner(request, userId):
user = Users.objects.get(user_id=userId)
message_trash = Messages.objects.filter(Q(message_user_reciever= user, message_sender_type='TRASH') | Q(message_user_sender=user, message_reciever_type='TRASH'))
return render(request, 'navigation_messages.html', {'user': user, 'message_trash': message_trash, 'type': 'trash'})
答案 0 :(得分:6)
在测试代码时,我只能通过交换来复制您的问题:
{% if request.session.user_email == message.message_user_reciever.user_email %}
的
{% if request.session.user_email ==message.message_user_reciever.user_email %}
注意缺少的空间。问题中的片段完全与模板中的片段完全相同吗?