2017-06-10 4 views
0

Zunächst all dies ist Django 1.11.2 und sekizai 0,1 und das ist in meinem settings.py:Sekizai TemplateSyntaxError wo kein sekizai verwendet wird

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 Kontext Prozessor, wie es enthalten sollte jedoch sein, die ich noch erhalten diese Fehlermeldung:

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. 

Was ärgerlicher ist, dass die spezifische Ansicht, Vorlage und Kind-Vorlage nicht für seine Rendering noch Last nicht verwendet sekizai. Der einzige Ort, an dem Sekizai in dieser Rendering-Kette verwendet wird, ist ganz oben im Haupt-Parent, dass diese spezifische Vorlage erweitert wird.

Irgendwelche Ideen, was das ist? Ich habe keine Ahnung, wie ich das lösen kann. Es gibt keinen offensichtlichen Grund, warum dieser Standort betroffen ist, ähnlich sind nicht und Standort, die eigentlich Sekizai verwenden, sind nicht so gut.

EDIT wie die Ansicht angefordert:

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) 
+0

Könnten Sie die Ansicht zeigen bitte – zaidfazil

+0

@Fazil Zaid: es ist da – Stefan

Antwort

3

Sie render() Shortcut-Funktion verwenden können,

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

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

render() ist eine brandneue Abkürzung für render_to_response in 1.3 versohlt, dass wird automatisch denRequestContext verwenden, den ich von nun an definitiv verwenden werde.

Ändern Sie die letzte Zeile,

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

die Linien entfernen,

context = RequestContext(request) 

context['usr_status'] = usr_status 
+0

Magie :-) ich so auf, dass konzentrierte Sekizai-Sache, das kam mir nicht einmal in den Sinn. Vielen Dank. – Stefan

Verwandte Themen