템플릿에 user.is_authenticated를 사용하도록 설정해야하는 모든 설정 파일에 이상한 문제가 있습니다. Django 템플릿 태그 + user.is_authenticated가있는 템플릿이 작동하지 않습니다.
나는 다음과 같은 템플릿 태그 코드가 있습니다{% block mainmenu %}
<ul>
{% for content in mcontent %}
{% if content.login_required %}
{% if content.to_page %}
<li><a href="/page/{{ content.to_page_slug }}">{{ content.name }}</a></li>
{% endif %}
{% if content.to_url %}
{% if content.external %}
<li><a href="{{ content.to_url }}" rel="external">{{ content.name }}</a></li>
{% else %}
<li><a href="{{ content.to_url }}">{{ content.name }}</a></li>
{% endif %}
{% endif %}
{% else %}
{% if content.to_page %}
<li><a href="/page/{{ content.to_page_slug }}">{{ content.name }}</a></li>
{% endif %}
{% if content.to_url %}
{% if content.external %}
<li><a href="{{ content.to_url }}" rel="external">{{ content.name }}</a></li>
{% else %}
<li><a href="{{ content.to_url }}">{{ content.name }}</a></li>
{% endif %}
{% endif %}
{% endif %}
{% endfor %}
</ul>
{% if user.is_authenticated %}
JEEEEEEEJ LOGGED IN
{% else %}
Not logged in
{% endif %}
{% endblock %}
그러나 내가 로그인 한 때 항상 심지어 로그인하지 않음 반환 다음과 같이
from django import template
from progmatic.cms.models import navigation, navigation_item
from django.template.defaultfilters import slugify
from django.shortcuts import render_to_response
from django.template import RequestContext
register = template.Library()
""" Gets the menu items you have entered in the admin.
No arguments are accpeted"""
def get_hoofd_menu():
menu = navigation.objects.get(slug = "hoofd-menu");
mcontent = navigation_item.objects.filter(parent_menu = menu);
return { 'mcontent' : mcontent }
def get_sub_menu(menu):
menu = navigation.objects.get(slug = slugify(menu))
mcontent = navigation_item.objects.filter(parent_menu = menu)
c = RequestContext(request, { 'mcontent': mcontent,})
return render_to_reponse('menu.html', RequestContext(request, { 'mcontent' : mcontent }))
register.inclusion_tag('menu.html')(get_hoofd_menu)
register.inclusion_tag('menu.html')(get_sub_menu)
그리고 템플릿 (menu.html를)입니다 in ... 누구든지이 코드에 어떤 문제가 있는지 실마리가 있습니까?
미리 감사드립니다.
인사말, Bloeper
업데이트 : 코드 내가 게시 동일한 (하나입니다 ...하지만 지금은 오류가 ... 그래서 개선입니다.그것은 말합니다 : 렌더링하는 동안 예외가 발생했습니다 : 글로벌 이름 '요청'이 정의되지 않았습니다 그리고 응답 부분에 렌더링됩니다 : – Bloeper