title: How do I add information from javascript variables to Django ModelForm input?
body: <p>I am building a web application using Django. The page shows a large leaflet map, in which users can select one out of several layers. I want users to be able to select a layer, click on the map and add a note to that location and that layer.</p>
  
  <p>I've created a model form, which holds the note itself. This works fine, and saves to my database. However, I need to also include the currently selected layer and mouse-click-location, which is readily available as a JS variable. How do I pass this on in Django?</p>
  
  <p>My <code>views.py</code> holds the following:</p>
  
  <pre><code>if request.method == 'POST':
          form = MapNoteForm(request.POST)
          if form.is_valid():
              form.save()
      else:
          form = MapNoteForm()
  </code></pre>
  
  <p>And <code>forms.py</code>:</p>
  
  <pre><code>class MapNoteForm(forms.ModelForm):
      note = forms.CharField()
  
      class Meta:
          model = MapNote
          fields = ('note',)
  </code></pre>
  
  <p>Finally, the relevant section of the template:</p>
  
  <pre><code>  map.on('click', function (e) {
        var MapNote = L.popup();
        var content = '&lt;form method="post"&gt; {% csrf_token %} {{form}} &lt;br&gt; &lt;button type="submit"&gt; Save&lt;/button&gt;'
        MapNote.setContent(content);
        MapNote.setLatLng(e.latlng); //calculated based on the e.layertype
        MapNote.openOn(map);
        })
  </code></pre>
  
  <p>I'm kind of looking to reverse the workings of the Django-view, trying to pass something from the template to Django, instead of vice versa. What would be the best approach here?</p>