Answer the question
In order to leave comments, you need to log in
Display products on homepage in Django-Oscar?
When using Django-Oscar, there was a clear problem with displaying a list of products on the main page.
The standard method doesn't work because of the session check protection (request.strategy.fetch_for_product(product)):
When I fetch the products in the catalog everything works fine. When I try to do this for the main page, either the list is empty or an error occurs.
If you use the method from the documentation (inserting a block of content), an error occurs all the time:
'str' object has no attribute 'strategy'
The error is in this code that checks the session:
from django import template
register = template.Library()
@register.assignment_tag
def purchase_info_for_product(request, product):
if product.is_parent:
return request.strategy.fetch_for_parent(product)
return request.strategy.fetch_for_product(product)
@register.assignment_tag
def purchase_info_for_line(request, line):
return request.strategy.fetch_for_line(line)
Answer the question
In order to leave comments, you need to log in
So far I have found this WORKAROUND SOLUTION. Through app.py, redefine the home page url by replacing it with a directory. In this version, the goods are shown without any errors.
But there was another problem. Updating the cart quantity raises a 500 error with reference to this piece of code:
def purchase_info_for_line(request, line):
return request.strategy.fetch_for_line(line)
Checking for the error shows that no strategy is passed in the line.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question