[英]Trying to pass django-oscar products to custom template
我正在使用django-oscar應用程序的分叉版本(具有自定義模型)來開發自定義模板。
我試圖從產品表開始顯示所有產品的列表。 我查看了django-oscar模板,但是由於它們依賴於許多自定義的tempaltetag,我發現重寫所有內容以與模型一起使用太復雜。
這就是我的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
arg。 似乎您需要將上下文添加到render
。
嘗試:
context={'prodlist': prodlist}
return HttpResponse(template.render(context))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.