1

I am running Django 1.9.6 If I try to use {{ request.path }} in my templates the var/tag is empty

Here is my settings.py

TEMPLATES = [
{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [
        os.path.join(BASE_DIR, '_templates'),
    ],
    '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',
            'django.template.context_processors.i18n',
        ],
        'builtins': ['django.templatetags.i18n']
    },
},

]

I read that after version 1.8 you need only to include 'django.template.context_processors.request' and you will have the var running in your templates

I manage to fix the issue if in my VIEW i add

return render_to_response('admin-users/events.html', {}, context_instance=RequestContext(request))

What am I doing wrong, because I read many answers which say that I don't have to add RequestContext?

Alasdair
  • 298,606
  • 55
  • 578
  • 516
user43506
  • 155
  • 3
  • 11

1 Answers1

3

Use the render method instead, it automatically uses a RequestContext to render the template.

 return render(request, 'admin-users/events.html', {}) 

The render_to_response shortcut is not recommended any more.

Alasdair
  • 298,606
  • 55
  • 578
  • 516