PacktPublishing / Django-3-by-Example

Django 3 by Example (3rd Edition) published by Packt
https://djangobyexample.com/
MIT License
716 stars 687 forks source link

Chapter 5 Bookmarks problem with <li {% if section == 'dashboard' %} class="selected"> #104

Open smtoff opened 3 years ago

smtoff commented 3 years ago

Just going through the book and came across this problem Page 206. Using Pycharm community and Windows 10. It is saying the template tag {% if section == 'dashboard' %} is not allowed inside the \<li> html tag. Tried to find a solution online but not very helpful especially with combination of css, html and django template language. Have a workaround but it's a bit messy and I am trying to get through the book so wondered if there was a solution. Have changed each of the following

  <li {% if section == "dashboard" %}class="selected"{% endif %}>
    <a href="{% url "dashboard" %}">My dashboard</a>
  </li>

to

      {% if section == 'dashboard' %}
        <li  class="selected">
        <a href="{% url 'dashboard' %}">My dashboard</a>
        </li>
      {% else %}
        <li>
        <a href="{% url 'dashboard' %}">My dashboard</a>
        </li>
      {% endif %}

As you can see code is now a bit messy any other way this can be done? Thanks

smtoff commented 3 years ago

Thanks but think I changed the double quotes in the original as well and still had problem. Pycharm and django gave definite error messages that stated the {% was not allowed in the html tag type.

diegobarbo commented 2 years ago

Same issue too.. sadly for I can't find a solution all over the internet.