Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'd like to use request.META.get('HTTP_REFERER') within template.

My template source:

<!-- this is login.html -->
{% extends "base.html" %}
{% block title %}django bookmark- login{% endblock %}
{% block head %}login{% endblock %}
{% block content %}
    {% if form.errors %}
    <p>try again!</p>
    {% endif %}
    <form method="post" action=".">{% csrf_token %}
        <p><label for="id_username">username:</label>
        {{ form.username }}</p>
        <p><label for="id_password">password:</label>
        {{ form.password }}</p>
        <input type="hidden" name="next" value="/<!-- I WANT TO USE 'HTTP_REFERER' HERE -->" />
        <input type="submit" value="login" />
    </form>
{% endblock %}

How what should I do?

urlpatterns = patterns('', (r'^login/$', 'django.contrib.auth.views.login'),
like image 544
chobo Avatar asked Dec 23 '12 10:12

chobo


People also ask

What is request Meta get (' Http_referer ')?

get notation is to specify a default value of no value is present. E.g.: request. META. get("HTTP_REFERER", "localhost") would cause it to either return the actual value of HTTP_REFERER or return localhost if there is no HTTP_REFERER.

What is request method in Django?

Django uses request and response objects to pass state through the system. When a page is requested, Django creates an HttpRequest object that contains metadata about the request. Then Django loads the appropriate view, passing the HttpRequest as the first argument to the view function.


1 Answers

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 }}

like image 199
Daniel Roseman Avatar answered Oct 26 '22 12:10

Daniel Roseman