Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django模板如果条件失败_Django_Templates_Conditional - Fatal编程技术网

Django模板如果条件失败

Django模板如果条件失败,django,templates,conditional,Django,Templates,Conditional,我不明白为什么if条件之间的代码没有显示。如果没有条件,代码显示良好 {% if current_user_is_not_crew %} <p> <form action="/commit/" method="post" id="event-commit"> <input type="hidden" name="event_id" value="{{ event.id }}"> <input type="submit" value="Commit to

我不明白为什么if条件之间的代码没有显示。如果没有条件,代码显示良好

{% if current_user_is_not_crew %}
<p>
<form action="/commit/" method="post" id="event-commit">
<input type="hidden" name="event_id" value="{{ event.id }}">
<input type="submit" value="Commit to this event">
{% csrf_token %}
</form>
</p>
{% endif %}
在视图中,它向我显示了它。views.py如下所示:

@login_required
def event(request, event_id):
    event = Event.objects.get(pk=event_id)
    crew = event.userprofile_set.all()
    current_user = request.user.get_profile()
    if current_user in crew:
         current_user_is_not_crew = False
    else:
         current_user_is_not_crew = True
    context = RequestContext(request)
    context['event'] = event
    context['crew'] = crew
    context['current_user'] = current_user_is_not_crew
    return render_to_response('event.html', context)

您能提供帮助吗?

传递给模板的变量是
当前用户
,而不是
当前用户


模板if块应该引用
当前用户

传递给模板的变量是
当前用户
,而不是
当前用户\u不是\u乘员


您的模板if块应该引用当前用户

谢谢。我自己就记下来了。太基本了!谢谢我自己就记下来了。太基本了!
@login_required
def event(request, event_id):
    event = Event.objects.get(pk=event_id)
    crew = event.userprofile_set.all()
    current_user = request.user.get_profile()
    if current_user in crew:
         current_user_is_not_crew = False
    else:
         current_user_is_not_crew = True
    context = RequestContext(request)
    context['event'] = event
    context['crew'] = crew
    context['current_user'] = current_user_is_not_crew
    return render_to_response('event.html', context)