Home > Enterprise >  How to print Json data to Django template
How to print Json data to Django template

Time:10-03

{
    '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

CodePudding user response:

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 %}
  • Related