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

394
Views
Cómo pasar variables de view.py a javascript sin usar render() en django

return render(request, 'index.html', {"flag": flag, "form": form})

Quiero pasar el valor de la bandera que debe ser leído por javascript para cambiar el estilo de un elemento en la plantilla, pero desde que se volvió a renderizar, el valor de la bandera se pierde y se vuelve a establecer en "ninguno", ¿hay alguna forma de no usar renderizar y pasar el variable a una url donde la página ya está renderizada

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

In your javascript file use ajax method to call your views.py, $.ajax({ type: "GET", method GET or POST url: "/url_name/", //url of site no need to enter full site data: { 'key': value, // data you want to pass if any }, contentType: 'application/json', success: function (response) { console.log(response.flag) // Gives value of flag }, error: function (data) { console.log('error'); } });; In your views.py you can pass your flag value as JSON response, def view_name(response): return JsonResponse({'flag': flag }, content_type='application/json')
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!