简体   繁体   English

Django:如何在视图中获取用户坐标(纬度、经度)?

[英]Django: How to get a users coordinates (latitude, longitude) in a view?

I need to be able to check the user's location before determining where their redirect will be sent.在确定他们的重定向将被发送到哪里之前,我需要能够检查用户的位置。 Is there an easy way to do this in Django/Python?在 Django/Python 中有没有一种简单的方法可以做到这一点?

views.py视图.py

@login_required
def update(request):
    if users coords in range(....):
       form = UpdateForm(request.POST or None)
       if request.method == "POST":
           if form.is_valid():
               update = form.save(commit=False)
               update.user = request.user
               update.save()
               value = form.cleaned_data['update']
               return redirect('main-home')
       return render(request, "main/update.html", {'form': form})
   else:
       return render(request, "main/error.html")

Try尝试

   from django.contrib.gis.utils import GeoIP

    g = GeoIP() 
    lat,lng = g.lat_lon(user_ip)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 给定Python中的坐标(经纬度)如何得到大陆? - How to get the continent given the coordinates (latitude and longitude) in Python? 如何从经纬度坐标列表中获取城市、state 和国家? - How to get city, state, and country from a list of latitude and longitude coordinates? 如何将经度、纬度、高程转换为笛卡尔坐标? - How to convert Longitude,Latitude, Elevation to Cartesian coordinates? 如何将字符串坐标分成 2 个列表:纬度和经度 - How to separate string coordinates into 2 lists: Latitude and Longitude 如何从Django GeoIP中的经度和纬度获取地址? - How to get Address from Latitude & Longitude in Django GeoIP? 如何使用 python 获取纬度和经度 - How To Get Latitude & Longitude with python 如何过滤具有一定半径内的纬度和经度坐标的django模型 - How to filter a django model with latitude and longitude coordinates that fall within a certain radius Geo Django从纬度和经度获得城市 - Geo Django get cities from latitude and longitude 如何从JSON格式的API的经纬度坐标中获取一个点的几何形状 - How to get the geometry of a point from the latitude and longitude coordinates of an API in JSON format 如何根据经度或纬度过滤Django GeopositionField - How to filter Django GeopositionField based on longitude or latitude
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM