python - Pass a dictionary from Djanjo view to another view via javascript -


i have view passes dictionary (along couple of forms , strings) html template. template has js file. accessing dictionary in js this:

<script type = "text/javascript">      var request_dict = {{request_dict|safe}};  </script> 

now, want pass on view via post(not necessarily, can change). format of request.post in second view should dictionary inside dictionary. dictionary(request_dict) comes list instead of dictionary.

how can resolve this? have use json? please mention if explanation wierd.

use json, safe.

view:

retutn render(request, 'template.html', {     'request_dict': json.dumps(request_dict), } 

templete:

<script type = "text/javascript">      var request_dict = json.parse('{{request_dict|safe}}'); </script> 

Comments

Popular posts from this blog

html - Difficulties with background-image property -

visual studio code - What does the isShellCommand property actually do and how should you use it? -

ios - Segue not passing data between ViewControllers -