Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

180
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda