Adding request object info to a template


/ Published in: Django
Save to your folder(s)



Copy this code and paste it in your HTML
  1. ## settings.py
  2. TEMPLATE_CONTEXT_PROCESSORS = (
  3. "django.contrib.auth.context_processors.auth",
  4. "django.core.context_processors.debug",
  5. "django.core.context_processors.i18n",
  6. "django.core.context_processors.media",
  7. "django.core.context_processors.static",
  8. "django.contrib.messages.context_processors.messages",
  9. "django.core.context_processors.request",
  10. )
  11.  
  12.  
  13. ## views.py
  14. from django.template import RequestContext
  15.  
  16. def home(request):
  17. return render_to_request('home.html', {}, context_instance=RequestContext(request))
  18.  
  19.  
  20. ## home.html
  21. <div id="navigation">
  22. <a class="{% ifequal request.path "/" %}active{% endifequal %}" href="/">Home</a>
  23. <a class="{% ifequal request.path "/services/" %}active{% endifequal %}" href="/services/">Services</a>
  24. <a class="{% ifequal request.path "/contact/" %}active{% endifequal %}" href="/contact/">Contact</a>
  25. </div>

URL: http://gnuvince.wordpress.com/2007/09/14/a-django-template-tag-for-the-current-active-page/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.