Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

182
Views
passing latitude and longitude from javascript or html to Django view

How to pass lat and lng to Django view without button click

pos = {lat: position.coords.latitude, lng: position.coords.longitude,};

I am working on a Django project and trying to get the current location of the user. i have a javascript function that returns the latitude and longitude , but i cannot pass them to Django as variables to save them or to do anything with them. I am using google maps api.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

**You can use Django view parameter to pass some data to your views : **

views.py

def coordinates(request, lat, long):
    // You may try to convert the lat and long variables
    // in the good type, i suppose here they are float
    my_lat, my_long = Float(lat), Float(long)
    context = {'lat': my_lat, 'long': my_long}
    
    return render(request, 'coordinates.html', context)

urls.py

from app_name import views

path('coordinates/<str:lat>/<str:long>/', views.coordinates, name='coordinates')

NB : I passe the lat and long here as string, but in the view i convert them with Float(). And this is an example of url: http://localhost:8000/coordinates/3.45/4.57

.html

<section>
    The latitude is : {{ lat }}
    <br>
    The longitude is : {{ long }}
</section>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!