简体   繁体   中英

How do I create pretty url from the GET parameters in Django?

my query string is generated by a form with name and age, that looks something like this,

www.example.com/?name=Martin&age=19&place=RU

the form,

<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>

and I want to make the submitted url to django to be

www.example.com/Martin/19/RU

how can I do this? what should I modify on the form or on the urls.py ?

thanks

<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>

And in your html, you need something like this:

<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>

I guess this should do the trick.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM