[Answered ]-How do I use context_instance in my template

2πŸ‘

βœ…

The whole point of the context processors is that they automatically add the elements to the context. So you can just use {{ request.host }} or whatever directly in the template.

Edit after comment No, this has nothing to do with generic views. Generic views act in exactly the same way as your own views that use RequestContext as you show above. If you want to make the request object available automatically in your views all you need to do is to add the code below to your settings.py – hard to see how this could be any quicker.

TEMPLATE_CONTEXT_PROCESSORS = (
    "django.contrib.auth.context_processors.auth",
    "django.core.context_processors.debug",
    "django.core.context_processors.i18n",
    "django.core.context_processors.media",
    "django.contrib.messages.context_processors.messages",
    "django.core.context_processors.request"
)

(This is just the default list of context processors as described in the docs, with the request one added.)

Leave a comment