向模板添加请求对象信息
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了向模板添加请求对象信息相关的知识,希望对你有一定的参考价值。
## settings.py 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.contrib.messages.context_processors.messages", "django.core.context_processors.request", ) ## views.py from django.template import RequestContext def home(request): ## home.html <div id="navigation"> <a class="{% ifequal request.path "/" %}active{% endifequal %}" href="/">Home</a> <a class="{% ifequal request.path "/services/" %}active{% endifequal %}" href="/services/">Services</a> <a class="{% ifequal request.path "/contact/" %}active{% endifequal %}" href="/contact/">Contact</a> </div>
以上是关于向模板添加请求对象信息的主要内容,如果未能解决你的问题,请参考以下文章