2012-08-22 110 views
0

我无法弄清为什么if条件之间的代码没有显示。没有条件的代码显示罚款。如果条件失败,Django模板

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

我知道变量current_user_is_not_crew是正确的,因为我曾与调试:

Assert False, locals() 
的观点,这表明我这

。 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) 

你能帮忙吗?

回答

4

您传递给模板的变量是current_user而不是current_user_is_not_crew

您的模板,如果块应该引用current_user

+0

谢谢。只是自己的时钟。如此基础! – KindOfGuy