'User draw rectangle on leaflet map and post the coordinates on django form

I would like to create a djagno app, which will enable users to draw a rectangle on a leafet map and post the coordinates in order to create a vector. Firtsly I have created the form.py file:

from django import forms

class CoordinatesForm(forms.Form):
    lat_max = forms.FloatField()
    lat_min = forms.FloatField()
    lon_max = forms.FloatField()
    lon_min = forms.FloatField()

I set the post method in the views,py file:

if request.method == 'POST':
    form = CoordinatesForm(request.POST)

and I have created a leaflet map:

<form action="" method="post" enctype="multipart/form-data">
        {% csrf_token %}

<script type="text/javascript">
        function map_init(map, options) {
          var drawnItems = new L.FeatureGroup();
          map.addLayer(drawnItems);
          var drawControl = new L.Control.Draw({
          edit: {
            featureGroup: drawnItems,
          },
          draw: {
            circle: false,
            circlemarker: false,
            polygon: false,
            marker: false,
            polyline: false,
          }
        });
        map.addControl(drawControl);
        }
        </script>
{% leaflet_map "yourmap2" callback="window.map_init"%}
<button type="submit">Submit</button>
</form>

Is there any way to submit the coordinates on click the button?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source