An instance of django passing values to a template and then receiving and operating with JS

  • 2020-10-07 18:45:46
  • OfStack

Use django to pass values to the template today, and then use js to handle 1. For the record.

The value is passed to the template using the json.dumps () method.


import json 
return render(request,'wauth/freetime.html', {'slot_ids': json.dumps(slot_ids)}) 

Receive the value from django with JSON.parse ().


var slot_ids = JSON.parse('{{ slot_ids|safe }}'); 

Related articles: