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

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -