Is it possible to make a django template URL aware without javascript?
For example, I would like to modify the css class to “active” for a certain tab or pill in twitter bootstrap.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you have
requestavailable in context then you can use request.path within the template to know the url and make css classactiveorinactivebased on that.You need to add
django.core.context_processors.requestin yourTEMPLATE_CONTEXT_PROCESSORSin project settings.Alternatively just pass a
page_namein request context and use that.As
ariepointed out: check django-activelink which basically seems to use the same above approach I mentioned but it adds some template tags on top.