Django:如何在视图中获取用户坐标(纬度、经度)?
Django: How to get a users coordinates (latitude, longitude) in a view?
我需要能够在确定将重定向发送到何处之前检查用户的位置。在 Django/Python 中有没有简单的方法来做到这一点?
views.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")
尝试
from django.contrib.gis.utils import GeoIP
g = GeoIP()
lat,lng = g.lat_lon(user_ip)
我需要能够在确定将重定向发送到何处之前检查用户的位置。在 Django/Python 中有没有简单的方法来做到这一点?
views.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")
尝试
from django.contrib.gis.utils import GeoIP
g = GeoIP()
lat,lng = g.lat_lon(user_ip)