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