如何在模板中使用request.META.get('HTTP_REFERER')? [英] How do I use request.META.get('HTTP_REFERER') within template?

查看:627
本文介绍了如何在模板中使用request.META.get('HTTP_REFERER')?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在模板中使用 request.META.get('HTTP_REFERER')

我的模板来源:

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

我应该怎么做?

urlpatterns = patterns('', (r'^login/$', 'django.contrib.auth.views.login'),


推荐答案

不需要获取 request.META 是一个字典,并且与所有字典一样,您可以使用点符号在模板中执行字段查找: {{request.META.HTTP_REFERER}}

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

这篇关于如何在模板中使用request.META.get('HTTP_REFERER')?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆