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

226
Views
Pasar variables de Django a javascripts

Estoy atascado en un problema, quiero pasar la variable django a javascripts pero no puedo.

vistas.py

 def dashboard_view(request): months_before = 5 now = datetime.utcnow() from_datetime = now - relativedelta(months=months_before) modified_from_datetime = from_datetime.replace(day=1, hour=0, minute=0, second=0, microsecond=0) month = Btdetail.objects.filter(DatePur__gte=modified_from_datetime).count() return render(request, "dashboard.html", {'month': month})

Quiero incrustar el valor del mes en los datos de javascripts

mi función de secuencia de comandos html es

 <script> var xValues = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]; new Chart("myChart3", { type: "line", data: { labels: xValues, datasets: [{ data: [5,10,20,15,20,5,15,40,10,12,24,35], borderColor: "red", fill: false }] }, options: { legend: {display: false} } }); </script>

en realidad, quiero crear una barra de área, todo está bien, pero las funciones de javascript no pueden obtener valor de la base de datos de django y si hay otra forma de hacerlo, dígame [1]: https://i.stack.imgur.com/ 9bJzE.jpg

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

0

en su anypage.html dentro de la etiqueta <body> </body>

 <body> <p> text for example </p> <div> some divs </div> <script type="text/javascript"> var month_count = {{ month }}; </script> </body>

iniciará la variable month_count en su anypage.html y podría usarla con javascripts dentro de este anypage.html

about 4 years ago · Juan Pablo Isaza Report

0

vistas.py
 import json def your_page(request): context = { "some_list": json.dumps([1,2,3]), } return render(request, "your_template.html", context)
javascript
 <script> const some_list = JSON.parse(`{{some_list|safe}}`); </script>
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!