django-ecommerce-project icon indicating copy to clipboard operation
django-ecommerce-project copied to clipboard

template base.html unresolved variable

Open alexakarpov opened this issue 3 years ago • 2 comments

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 avatar Jan 10 '22 02:01 alexakarpov

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 avatar Jan 10 '22 02:01 alexakarpov

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 =)

alexakarpov avatar Jan 10 '22 03:01 alexakarpov