如何从Django中的GET参数创建漂亮的url?

所有的Vaiіtы

我的查询字符串是由具有名称和年龄的表单生成的,看起来像这样,

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

谢谢

日本动漫Sharma
<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>

我想这应该可以解决问题。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章