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
Post a Comment