[英]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.