title: Django - Render to Response
body: <p>I am using the following code in my Django view</p>
  
  <pre><code>data = {'d':['a','b','c']}
  return render_to_response('login/invalid.html',data)
  </code></pre>
  
  <p>Now i want my <code>invalid.html</code> page to have the code to convert the list <code>['a','b','c']</code> to a javascript variable array so that i can populate a dropdown menu. But i cannot convert these elements into a javascript array.</p>
  
  <pre><code>var arr = "{{ 'd' }}"
  </code></pre>
  
  <p>takes the list as a string and not as an array
  Please help</p>
  
  <hr>
  
  <p>This code creates a drop down using an array</p>
  
  <pre><code>&lt;select &gt;
                &lt;script type="text/javascript"&gt;
  
                {% autoescape off %}
                var veg = {{ d }}
                {% endautoescape %}
  
                   for (i = 0; i &lt; veg.length; i++) {
                       document.write('&lt;option&gt;')
                       document.write(veg[i])                   
                       document.write('&lt;/option&gt;')                    
                  }
               &lt;/script&gt;            
           &lt;/select&gt;
  </code></pre>
  
  <hr>
  
  <pre><code>                d = json.dumps(['a','b','c'])
                  #d = serializers.serialize("json", ['a','b','c'])
                  #data={"d":json.dumps(['1','2','3','4'])}
                  #data={}
                  data = {'d':d}
  
                  #data["read"] = json.dumps(",".join(['abc']))
  
                  #return render_to_response('login/invalid.html',json.dumps(data),context_instance=RequestContext(request))
  
                  return render_to_response('login/invalid.html',data,context_instance=RequestContext(request))
  </code></pre>