Unable to set up Jinja2 with Django -


i've installed django 1.9.7, , have pythons 3.4.3 , 2.7.10 on ubuntu.

these steps i've followed:

  1. made new project django-admin startproject testproject
  2. cd testproject/testproject
  3. made app within project django-admin startapp testapp
  4. made directory templates in app mkdir testapp/templates , added basic index.html template in there
  5. edited settings.py change template backend django.template.backends.jinja2.jinja2, editing line 57 of default settings file, , add testproject.testapp installed_apps; templates section therefore this:

    templates = [     {         'backend': 'django.template.backends.jinja2.jinja2',         'dirs': [],         'app_dirs': true,         'options': {             'context_processors': [                 'django.template.context_processors.debug',                 'django.template.context_processors.request',                 'django.contrib.auth.context_processors.auth',                 'django.contrib.messages.context_processors.messages',             ],         },     }, ] 
  6. edited urls.py, adding from testproject.testapp import views , url pattern url(r'^$', views.index),

  7. edited testapp/views.py adding

    def index(request):     return render(request, 'index.html') 
  8. cd ..

  9. ran server python3 manage.py runserver, or python manage.py runserver -- similar effect
  10. take browser http://localhost:3000

i error. on command line this:

internal server error: / traceback (most recent call last):   file "/usr/local/lib/python3.4/dist-packages/django/template/utils.py", line 86, in __getitem__     return self._engines[alias] keyerror: 'jinja2' 

followed exception caused "during handling of above exception", matches exception see in browser:

environment:   request method: request url: http://localhost:3000/  django version: 1.9.7 python version: 3.4.3 installed applications: ['django.contrib.staticfiles', 'testproject.testapp', 'webpack_loader'] installed middleware: ['django.middleware.security.securitymiddleware',  'django.middleware.common.commonmiddleware',  'django.middleware.clickjacking.xframeoptionsmiddleware']    traceback:  file "/usr/local/lib/python3.4/dist-packages/django/template/utils.py" in __getitem__   86.             return self._engines[alias]  during handling of above exception ('jinja2'), exception occurred:  file "/usr/local/lib/python3.4/dist-packages/django/core/handlers/base.py" in get_response   174.                     response = self.process_exception_by_middleware(e, request)  file "/usr/local/lib/python3.4/dist-packages/django/core/handlers/base.py" in get_response   172.                     response = response.render()  file "/usr/local/lib/python3.4/dist-packages/django/template/response.py" in render   160.             self.content = self.rendered_content  file "/usr/local/lib/python3.4/dist-packages/django/template/response.py" in rendered_content   135.         template = self._resolve_template(self.template_name)  file "/usr/local/lib/python3.4/dist-packages/django/template/response.py" in _resolve_template   90.         new_template = self.resolve_template(template)  file "/usr/local/lib/python3.4/dist-packages/django/template/response.py" in resolve_template   80.             return select_template(template, using=self.using)  file "/usr/local/lib/python3.4/dist-packages/django/template/loader.py" in select_template   55.     engines = _engine_list(using)  file "/usr/local/lib/python3.4/dist-packages/django/template/loader.py" in _engine_list   143.     return engines.all() if using none else [engines[using]]  file "/usr/local/lib/python3.4/dist-packages/django/template/utils.py" in   110.         return [self[alias] alias in self]  file "/usr/local/lib/python3.4/dist-packages/django/template/utils.py" in <listcomp>   110.         return [self[alias] alias in self]  file "/usr/local/lib/python3.4/dist-packages/django/template/utils.py" in __getitem__   101.             engine = engine_cls(params)  file "/usr/local/lib/python3.4/dist-packages/django/template/backends/jinja2.py" in __init__   35.         self.env = environment_cls(**options)  exception type: typeerror @ / exception value: __init__() got unexpected keyword argument 'context_processors' 

i similar traces python 2.

i found this question has similar error message (keyerror: 'jinja2') seems separate problem, , this bug report has same error again solution install jinja2, jinja2 installed. @ least, can run python or python3 , import jinja2. pip says jinja2 date.

i must missing crucial -- ideas?

the error context_processors because jinja2 backend not support argument.

you should add additional backend templates setting, rather replacing existing backend django jinja2. see this answer more information. if replace existing backend, apps require django templates not work, including admin.

finally, jinja2 backend templates in testapp/jinja2, not testapp/templates.


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -