I am currently working on a personal blog in Django to get better at web programming, but I have encountered a slight problem. My idea was to make the webpage able to know which menu element is the active one, passing an argument from the views.py and to the template. Thus, I am here to ask why that might be so.
This is my template:
{% block menu %}
<style> li a:nth-child({{ active }}) { text-decoration: underline; } </style>
<li><div id="title"><span>{</span> <a href="#">Title</a> <span>}</span></div></li>
<li><a href="/">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
<li><a href="#">Work</a></li>
{% endblock menu %}
And here is my views.py (for the specific page):
def detail(request, blog_id):
blog = get_object_or_404(BlogPost, pk=blog_id)
return render(request, 'blogs/post.html', {'blog': blog, 'active': 1})
I have tried targetting the nth-child of the li's, but that didn't work either. I have also tried putting in fixed numbers as a parameter for the nth-child. Alas, to no avail.
Can anyone help me? Are there any better ways to do this?