Andres Gallardo Andres Gallardo - 6 months ago 40
Python Question

Django tables 2: error django.template.context_processors.request

I installed the module tables 2 and i have the next problem:


Exception Value: Tag {% querystring %} requires
django.template.context_processors.request to be in the template
configuration in settings.TEMPLATES[]OPTIONS.context_processors) in
order for the included template tags to function correctly.


My code is:

Settings.py

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR + '/llamadas/plantillas')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.core.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'django.template.context_processors.request',
],
},
},
]


Views.py

def home(request):
if request.user.is_authenticated():
llamadas = CallEntry.objects.all()
return render_to_response('inicio.html', {'llamadas': llamadas})
else:
return HttpResponseRedirect('/accounts/login/')


Inicio.html

{% load render_table from django_tables2 %}
<!doctype html>
<html>
<head>
<link rel="stylesheet" href="{{ STATIC_URL }}django_tables2/themes/paleblue/css/screen.css" />
</head>
<body>
{% render_table llamadas %}
</body>
</html>


Any suggestions?

Thanks !

Answer

The render_to_response shortcut is not recommended any more.

Use the render shortcut instead, so that the context processors are used.

return render(request, 'inicio.html', {'llamadas': llamadas})
Comments