title: How to read a view variable from javascript function
body: <p>I need to draw in a canvas an image taken from the database (actually more images, one for canvas). The image depend on the user but once the page is loaded it don't change so I could pass it in the view, if usefull. I don't know how to say to the javascript function which image to draw. </p>
  
  <p>My <code>models.py</code>:</p>
  
  <pre><code>class Forma(models.Model):
      name = models.CharField(max_length=64)
      percorso = models.ImageField(upload_to='/mypath', 
          blank=True, default='')
  </code></pre>
  
  <p>My <code>views.py</code>:</p>
  
  <pre><code>def homepage(request):
      ...
      tipo=user_profile.tipo
      forma_list=Forma.objects.filter(tipo=tipo)
      context_dict['forma_list']=forma_list
      return render(request, 'homepage.html', context_dict)
  </code></pre>
  
  <p>My <code>homepage.html</code>:</p>
  
  <pre><code>  &lt;script&gt;
    &lt;!--
      window.onload = function() {
        crea_image();
      };
    --&gt;
    &lt;/script&gt;
  
      ...
      &lt;canvas id='canvas1'&gt;
        Your browser does not support the HTML5 canvas tag.
      &lt;/canvas&gt;
  </code></pre>
  
  <p>My <code>script-jquery.js</code>:</p>
  
  <pre><code>function crea_image() {      
    // basically I want something like that:
    //var forme = context_dict['form_list']
  
    var canvas1 = document.getElementById("canvas1");
    var context = canvas1.getContext("2d");  
    var base = new Image();
    base.src = forme[0].percorso
    base.onload = function() {
    context.drawImage(base, 0, 0);
    };
  };
  </code></pre>
  
  <p>I search but I found reference to other file, like that</p>
  
  <pre><code>var xmlhttp = new XMLHttpRequest();
  var url = "myTutorials.txt";
  </code></pre>
  
  <p>or to url like that</p>
  
  <pre><code>xmlhttp.open("GET", url, true);
  </code></pre>
  
  <p>and I'm not sure if it's good for my situation.</p>