Reputation: 49
I have product_view.html file which contains
Product {{product.title}}
and I have view which have loaded information about model
template = loader.get_template(path)
context = {'title': product[0].title, 'description': product[0].description, 'image_url': product[0].image_url, 'quantity': product[0].quantity}
return HttpResponse(template.render(context, request))
How I can render data to product_view.html, so it shows product.title? Now it only shows "Product" on the page. I am very new to django and it's very flustrating that I can't even do that :(
Upvotes: 0
Views: 52
Reputation: 3970
first make everything simple and clear!
template = 'YourTemplateFolder/product_view.html'
context = {"product":product[0]}
return render(request, template, context)
for the template, to print anything inside of it just put the variable name inside of two curly brackets
{{ product.title }}
# product is the name you defined in context and by default it will take all of the variables attached to the original variable
and please in the future add more details to the question so people can help you instead of down-voting you.
Upvotes: 2