Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

160
Views
Django serialize object return array

Django serialize object return an array, and i cant get it in template with js

my view.py:

def MyExempleView(request):
    data = serializers.serialize("json", myModel.objects.all())
    context = {
        "data" : json.loads(data)
    }
    return render(request, 'consulta/myTemplateExemple.html', context=context)

my template:

{{ data|json_script:"data" }}

if ($("#data").length) {
    var data= JSON.parse(document.getElementById('data').textContent);
}

my result exemple:

"[{"key": "value"}, {"key2": "value2"}]"
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

i solved loading and dumping the json with python json:

in views:

"data" : data

and in js in template:

var data = JSON.parse(document.getElementById('data').textContent)
jsonResponse = JSON.parse(data)
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!