Sekizai TemplateSyntaxError, где sekizai не используется

Прежде всего это Django 1.11.2 и sekizai 0.1, и это в моих settings.py:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS':[],
        'APP_DIRS': True,
        'OPTIONS': {
            'builtins': ['mypage.templatetags.everywhere'],
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',

                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
                'sekizai.context_processors.sekizai',
                'django.template.context_processors.i18n',

            ],
        },
    },
]

Sekizai контекстный процессор включен, как и должно быть, однако я все еще получаю эту ошибку:

Traceback (most recent call last):
  File "/usr/lib/python2.7/wsgiref/handlers.py", line 85, in run
    self.result = application(self.environ, self.start_response)
  File "/home/ubuntu/workspace/project/apps/django/contrib/staticfiles/handlers.py", line 63, in __call__
    return self.application(environ, start_response)
  File "/home/ubuntu/workspace/project/apps/django/core/handlers/wsgi.py", line 157, in __call__
    response = self.get_response(request)
  File "/home/ubuntu/workspace/project/apps/django/core/handlers/base.py", line 124, in get_respon e
    response = self._middleware_chain(request)
  File "/home/ubuntu/workspace/project/apps/django/core/handlers/exception.py", line 43, in inner
    response = response_for_exception(request, exc)
  File "/home/ubuntu/workspace/project/apps/django/core/handlers/exception.py", line 93, in response_for_exception
    response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
  File "/home/ubuntu/workspace/project/apps/django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "/home/ubuntu/workspace/project/apps/django/core/handlers/base.py", line 249, in _legacy_get_response
    response = self._get_response(request)
  File "/home/ubuntu/workspace/project/apps/django/core/handlers/base.py", line 187, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/home/ubuntu/workspace/project/apps/django/core/handlers/base.py", line 185, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/ubuntu/workspace/hys/views/acc_settings.py", line 116, in horoscopedata
    context)
  File "/home/ubuntu/workspace/project/apps/django/shortcuts.py", line 21, in render_to_response
    content = loader.render_to_string(template_name, context, using=using)
  File "/home/ubuntu/workspace/project/apps/django/template/loader.py", line 68, in render_to_string
    return template.render(context, request)
  File "/home/ubuntu/workspace/project/apps/django/template/backends/django.py", line 66, in render
    return self.template.render(context)
  File "/home/ubuntu/workspace/project/apps/django/template/base.py", line 207, in render
    return self._render(context)
  File "/home/ubuntu/workspace/project/apps/django/template/base.py", line 199, in _render
    return self.nodelist.render(context)
  File "/home/ubuntu/workspace/project/apps/django/template/base.py", line 990, in render
    bit = node.render_annotated(context)
  File "/home/ubuntu/workspace/project/apps/django/template/base.py", line 957, in render_annotated
    return self.render(context)
  File "/home/ubuntu/workspace/project/apps/django/template/loader_tags.py", line 177, in render
    return compiled_parent._render(context)
  File "/home/ubuntu/workspace/project/apps/django/template/base.py", line 199, in _render
    return self.nodelist.render(context)
  File "/home/ubuntu/workspace/project/apps/django/template/base.py", line 990, in render
    bit = node.render_annotated(context)
  File "/home/ubuntu/workspace/project/apps/django/template/base.py", line 957, in render_annotated
    return self.render(context)
  File "/home/ubuntu/workspace/project/apps/classytags/core.py", line 153, in render
    return self.render_tag(context, **kwargs)
  File "/home/ubuntu/workspace/project/apps/sekizai/templatetags/sekizai_tags.py", line 91, in render_tag
    if not validate_context(context):
  File "/home/ubuntu/workspace/project/apps/sekizai/templatetags/sekizai_tags.py", line 44, in validate_context
    "You must enable the 'sekizai.context_processors.sekizai' template "
TemplateSyntaxError: You must enable the 'sekizai.context_processors.sekizai' template context processor or use 'sekizai.context.SekizaiContext' to render your templates.

Что еще более раздражает, так это то, что конкретный вид, шаблон и дочерний шаблон не используют и не загружают sekizai для его рендеринга. Единственное место, где используется sekizai в этой цепочке рендеринга, это самый верхний, в главном родительском элементе, где этот конкретный шаблон расширяется.

Есть идеи, что это? Я понятия не имею, как это решить. Нет очевидной причины, по которой это местоположение затрагивается, simmilar - нет, и местоположение, которое фактически использует sekizai, не так хорошо.

РЕДАКТИРОВАТЬ в соответствии с запросом:

def vvv(request):
    template = "settings/template.html"
    context = RequestContext(request)

    if request.user.is_authenticated():
        usr_status = get_user_status(request.user)
        context['usr_status'] = usr_status
        if model.objects.filter(user_id=request.user.id).exists():
            if usr_status ==VIP:
                data = model.objects.filter(user_id=request.user.id).order_by('-main')
                remaining = MAX_MAIN_VIP-model.objects.filter(user_id=request.user.id).count()
            else:
                data = model.objects.filter(user_id=request.user.id,main=True)
                remaining = MAX_MAIN_AUTH-model.objects.filter(user_id=request.user.id).filter(main=True).count()
        else:
            data = None
            remaining = None

        return render_to_response(template,
            {'form':Form, 'data':data,'remaining':remaining},
            context)

1 ответ

Решение

Вы могли бы использовать render() функция быстрого доступа,

https://docs.djangoproject.com/en/1.11/topics/http/shortcuts/

render(request, template[, dictionary][, context_instance][, content_type][, status][, current_app])

render() - это совершенно новый ярлык для render_to_response в 1.3, который будет автоматически использовать RequestContext, который я буду использовать с этого момента.

Изменить последнюю строку,

return render(request, template, {'form':Form, 'data':data,'remaining':remaining, 'usr_status':usr_status})

Удалить строки,

context = RequestContext(request)

context['usr_status'] = usr_status
Другие вопросы по тегам