cho*_*obo 10 django django-templates
我想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 %}
Run Code Online (Sandbox Code Playgroud)
我该怎么办?
urlpatterns = patterns('', (r'^login/$', 'django.contrib.auth.views.login'),
Run Code Online (Sandbox Code Playgroud)
添加django.core.context_processors.request您的设置文件TEMPLATE_CONTEXT_PROCESSORS然后您就可以使用requestin模板而无需在请求中明确传递它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
)
Run Code Online (Sandbox Code Playgroud)
你可以做的模板 {{request.META.HTTP_REFERER}}
| 归档时间: |
|
| 查看次数: |
16432 次 |
| 最近记录: |