How do I use request.META.get('HTTP_REFERER') within template?

ⅰ亾dé卋堺 提交于 2019-12-05 01:22:12
Daniel Roseman

There's no need for get.request.META is a dictionary, and as with all dictionaries, you can perform field lookup in the template using the dot notation: {{ request.META.HTTP_REFERER }}

Add django.core.context_processors.request in your settings file in TEMPLATE_CONTEXT_PROCESSORS then you would be able to use the request in template without explicitly passing it in request context.

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.core.context_processors.static',
    'django.core.context_processors.request', # this one
)

the in template you could do {{request.META.HTTP_REFERER}}

Actually the preferred way is to use the next parameter as documented here

You can do in your template something like this:

<input type="hidden" name="next" value="{{  request.GET.next }}" />
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!