我的提交表单如下:
<form id="form_id" method="POST" action="https://127.0.0.1:8000/api/node">
<h1>Add Node</h1>
<h4>Node ID</h4>
<div class="name">
<input type="text" name="name" placeholder="node id" id="node_id" />
</div>
<h1>Get the latitude and longitude of the node</h1>
<p>
latitude: <span id="latitude"></span><br />
longitude: <span id="longitude"></span>
</p>
<style>
#node1Map { height: 260px; }
</style>
<div id="node1Map"></div>
<script>
const mymap = L.map('node1Map').setView([0, 0], 1);
const attribution ='©: <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors';
const tileUrl = 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
const tiles = L.tileLayer(tileUrl, { attribution });
tiles.addTo(mymap);
// get coordinate
var latitude, longitude, marker;
mymap.on('click', function(e) {
if(marker) mymap.removeLayer(marker);
latitude = e.latlng.lat;
longitude = e.latlng.lng;
console.log(latitude);
console.log(longitude);
marker = L.marker([latitude, longitude]).addTo(mymap);
document.getElementById('latitude').textContent = latitude;
document.getElementById('longitude').textContent = longitude;
});
</script>
<h4>Location Address</h4>
<input type="text" id="location" />
<div class="btn-block">
<button type="submit" href="/">Submit</button>
</div>
</form>
</body>
</html>
我目前的情况是: 1.我提交了表单,然后表单中的数据将保存在我的django rest API(https://127.0.0.1:8000/api/node)中 2.页面重定向到https://127.0.0.1:8000/api/node中的django rest API页面。显示我保存的json数据。
但是我现在想要的是: 1.我提交了表单,然后表单中的数据将保存在我的django rest API(https://127.0.0.1:8000/api/node)中 2.页面未重定向到https://127.0.0.1:8000/api/node中的django rest API。但是重定向到我想要的另一个URL。例如:该页面将重定向到https://127.0.0.1:8000/listdata。
我该怎么做?
答案 0 :(得分:0)
从以下位置使用重定向功能:
from django.shortucts import redirect
return redirect(<your views function to were you went to send>)