Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

template base.html unresolved variable #4

Open
alexakarpov opened this issue Jan 10, 2022 · 2 comments
Open

template base.html unresolved variable #4

alexakarpov opened this issue Jan 10, 2022 · 2 comments

Comments

@alexakarpov
Copy link

alexakarpov commented Jan 10, 2022

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
Copy link
Author

alexakarpov commented Jan 10, 2022

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant