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'),
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.
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.
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 }}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With