How to save Mapbox routes in Django Model

I have an html page with a form and Mapbox. Below is a picture of what it looks like.

enter image description here

I want the user to fill out a form and then plot a route on the map (see screenshot). Both the data of this form and the route itself were saved to the database.

When filling out the form on the left, everything is successfully saved to the database. But I have a question, how to save the routes that I build on the Mapbox map. I checked through the Network in the browser inspector, and the API itself creates the Mapbox request.

enter image description here

But here's how to save it to my table... For example I have a table Route and the columns are id, latitude and longitude.

Perhaps tell me in which direction to think, tk. I broke my head that how to pull this data.

Maybe some project code will help you.

django views.py:

def getForm(request):
    form = RouteForm()
    if request.method == 'POST':
        form = RouteForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('home')
    return render(request, 'routes_form/route_form.html', {'form': form})

This question is rather for those who have worked with Mapbox or know something about it.

P.S. I'm still just learning and I just don't understand some things yet, but I tried to google something to the maximum.

Back to Top