[英]How do I create pretty url from the GET parameters in Django?
我的查詢字符串是由具有名稱和年齡的表單生成的,看起來像這樣,
www.example.com/?name=Martin&age=19&place=RU
表格,
<form action="" method="get">
Name: <input type="text" name="name"><br>
Age: <input type="text" name="age"><br>
Place <input type="text" name="place"><br>
<input type="submit" value="Submit">
</form>
我想將提交到django的網址設為
www.example.com/Martin/19/RU
我怎樣才能做到這一點? 我應該在form
或urls.py
上修改什么?
謝謝
<script>
function changeAction() {
var profile_form = document.getElementById('profileform');
if(profile_form) {
var txt = "http://www.example.com/";
var i;
for (i = 0; i < profile_form.length; i++) {
txt = txt + profile_form.elements[i].value + "/";
}
profile_form.action = txt;
}}
</script>
並且在您的html中,您需要這樣的內容:
<form action="" method="get" id="profileForm" onsubmit="changeAction()">
Name: <input type="text" name="name"><br>
Age: <input type="text" name="age"><br>
Place <input type="text" name="place"><br>
<input type="submit" value="Submit">
</form>
我想這應該可以解決問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.