veryacademy / django-ecommerce-project

The Django-Ecommerce is an open-source project initiative and tutorial series built with Python and the Django Framework.
MIT License
399 stars 278 forks source link

template base.html unresolved variable #4

Open alexakarpov opened 2 years ago

alexakarpov commented 2 years ago

I don't know, exactly, why the site keeps working, but once I've enabled debug logging server-side, there came in a flood of messages pointing to the same problem on lines 46 and 125:

           <li {% if category.slug == c.slug %}class="selected" {% endif %}>
              <a class="dropdown-item" href="{{ c.get_absolute_url }}">{{ c.name|title }}</a>

, where 'category' variable does not exist. The code above is taken from Chapter 10.

alexakarpov commented 2 years ago

I think the error occurred at some refactoring effort after the Part 01 - there, the context in category_list view has the variable that seems to have gone missing:

category = get_object_or_404(Category, slug=category_slug)

And at the Part 02's Final stage, the problem is already present

alexakarpov commented 2 years ago

Note: when on the page where a category is selected at the dropdown element (and it is also a part of a route), the view, category_list in this case, does add 'category' variable to the context, and there's no error. But the product_all has no such variable on the context, yet as it uses the same base.html, the problem duly manifests itself. A good debugging exercise =)