Created
October 1, 2012 12:44
-
-
Save lambdaman2/3811446 to your computer and use it in GitHub Desktop.
Django: Adding request object info to a template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## 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): | |
| return render_to_request('home.html', {}, context_instance=RequestContext(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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment