Rowkaha
Rowkaha

Reputation: 103

How to print Json data to Django template

{
    '4': [1, 'Product New', '450.00', '4'], 
    '6': [1, 'Products Hello', '4500.00', '6']
}

I receive data in my view.py:

using products = json.loads(data)

After that, i am trying to show each item's in Django templates. 4 and 6 is pro

Upvotes: 0

Views: 1146

Answers (1)

Sabil
Sabil

Reputation: 4510

You can try this:

data = {
    '4': [1, 'Product New', '450.00', '4'], 
    '6': [1, 'Products Hello', '4500.00', '6']
}

json_string = json.loads(data)
return render(request,'test.html',{'dataset':json_string})

HTML Part:

{% for key, value in dataset.items %}
{{key}}: {{value}}
{% endfor %}

Upvotes: 2

Related Questions