无法解析剩余的django模板

时间:2015-03-04 16:35:50

标签: django python-2.7 django-templates

我的模板循环中有一个条件,如下所示:

{% 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'})

1 个答案:

答案 0 :(得分:6)

在测试代码时,我只能通过交换来复制您的问题:

{% if request.session.user_email == message.message_user_reciever.user_email %}

{% if request.session.user_email ==message.message_user_reciever.user_email %}

注意缺少的空间。问题中的片段完全与模板中的片段完全相同吗?