带有获取请求表的友好URL [英] Friendly URL with get request form

查看:38
本文介绍了带有获取请求表的友好URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个简单的html表单:

i have this simple html form:

<form action="test/" method="get" accept-charset="utf-8">

    <input type="text" name="first" value="" id="first">
    <input type="text" name="second" value="" id="second">
    <input type="text" name="third" value="" id="third">

    <p><input type="submit" value="Continue &rarr;"></p>
</form>

当用户单击提交"按钮时,我想要获得这样的友好URL:

when user click submit button, i want to get friendly URL like this:

www.site.com/test/first/second/third

www.site.com/test/first/second/third

我该怎么做?

推荐答案

用户填写表单并单击继续"后最终到达的位置取决于您在 form 标记.您目前已将其设置为 test/.

Where the user ends up after filling out the form and clicking "Continue" depends on what you set the action attribute in your form tag to. You've currently set it to test/.

如果您希望它们以 test/< first_val>/< second_val>/< third_val>/结尾,那么您可以使用一些JavaScript(根据pythonFoo的回答),或者您可以使用test/指向的视图中重定向.HttpResponseRedirect"rel =" nofollow> HttpResponseRedirect :

If you want them to end up at test/<first_val>/<second_val>/<third_val>/, then you can either use some JavaScript (per pythonFoo's answer), or you can redirect in the view that test/ points to, using HttpResponseRedirect:

def test_view(request):
  return HttpResponseRedirect('/test/%s/%s/%s/' % request.POST['first'],
                                                  request.POST['second'],
                                                  request.POST['third])

这篇关于带有获取请求表的友好URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆