A
A
Aleksandr R2017-01-24 12:06:20
Django
Aleksandr R, 2017-01-24 12:06:20

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)

Please suggest working examples or workarounds.
UPD: The bug turned out to be in Django version=1.10.5. After rolling back to version 1.9.12, the error disappeared.
Goods are displayed on the main page through the automatic list of goods block.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander R, 2017-01-25
@alexhouse

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 question

Ask a Question

731 491 924 answers to any question