试图将 django-oscar 产品传递给自定义模板

Trying to pass django-oscar products to custom template

我正在使用 django-oscar 应用程序的分叉版本(具有自定义模型)开发自定义模板。

我正在尝试显示产品 table 中所有产品的列表,只是为了开始。我查看了 django-oscar 模板,但由于它们依赖于大量自定义 tempaltetags,我发现重写所有内容以使用我的模型太复杂了。

这是我的 views.py:

def product(request):
    template = loader.get_template('/home/mysite/django_sites/my_site/main_page/templates/main_page/product.html')
    prodlist = Product.objects.all()
    return HttpResponse(template.render({}, request), context={'prodlist': prodlist})

以及我在模板中用来尝试显示它的代码

{% for instance in prodlist%}
    <li>{{ instance.name }}</li>
{% endfor %}

但是,这给了我一个错误

TypeError at /product/ 
__init__() got an unexpected keyword argument 'context'

/product对应我在urls.py

中的产品视图

这是我根据教程和查看其他答案做出的最佳猜测。我哪里错了?

HttpResponse 没有 context 参数。 似乎您需要将上下文添加到 render.

尝试:

context={'prodlist': prodlist}
return HttpResponse(template.render(context))