如何通过ID将变量x从模板传递到我的视图? 我的模板
<button onclick="getLocation()">Try It</button>
<p id="demo" ></p>
<p id="demo1"></p>
<script>
var x = document.getElementById("demo");
var x1 = document.getElementById("demo1");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
x.innerHTML = position.coords.latitude
x1.innerHTML = position.coords.longitude
}
</script>
我的观点:
def RegisterOrder(request,ln):
user = request.user
if request.method == 'GET':
data = OrderRegister
return render(request, 'reg.html', {'formreg': data,'ln':ln})
else:
data = OrderRegister(request.POST)
if data.is_valid():
table = models.Order()
table.table_num_id = data.cleaned_data['table_num']
table.lan=ln
table.user_id=user.id
table.long_position=request.GET.get['demo']
table.save()