Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

183
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda