How to pass multiple values for a single URL parameter?

核能气质少年 提交于 2020-01-10 21:21:06

问题


Is it possible to pass multiple values for a single URL parameter without using your own separator?

What I want to do is that the backend expects an input parameter urls to have one or more values. It can me set to a single or multiple URLs. What is a way to set the urls parameter so it can have multiple values? I can't use my own separator because it can be part of the value itself.

Example: http://example.com/?urls=[value,value2...]

The urls parameter be set to just http://google.com or it can be set to http://google.com http://yahoo.com .... In the backend, I want to process each url as a separate values.


回答1:


http://.../?urls=foo&urls=bar&...

...

request.GET.getlist('urls')



回答2:


The following is probably the best way of doing it - ie, don't specify a delimited list of URLs, rather, use the fact you can specify the same param name multiple times, eg:

http://example.com/?url=http://google.co.uk&url=http://yahoo.com

The URL list be then be used and retrieved via request.GET.getlist('url')



来源:https://stackoverflow.com/questions/13261377/how-to-pass-multiple-values-for-a-single-url-parameter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!