Jake Rankin
Jake Rankin

Reputation: 744

Trying to pass django-oscar products to custom template

I'm working on a custom template using a forked version of django-oscar apps (to have custom models).

I am trying to display a list of all the products in the product table, just to start with. I looked at django-oscar templates but as they rely on a lot of custom tempaltetags I found it too complex to rewrite everything to work with my models.

This is what I have in my 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})

And the code I am using in my template to try and display it

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

However, this gives me an error

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

/product corresponds to my product view in my urls.py

This was my best guess from following tutorials and looking at other answers. What am I getting wrong?

Upvotes: 0

Views: 392

Answers (1)

Sergey Pugach
Sergey Pugach

Reputation: 5669

HttpResponse doesn't have context arg. Seems like you need to add context into render.

Try:

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

Upvotes: 1

Related Questions