从python中的URL获取查询字符串的最佳方式? [英] Best way to get query string from a URL in python?

查看:748
本文介绍了从python中的URL获取查询字符串的最佳方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个网址= http://stackoverflow.com/questions/ask?next=1& value = 3
现在我需要从这个url获取查询字符串。
我不想使用request.META获取查询字符串。

I have this url = http://stackoverflow.com/questions/ask?next=1&value=3 Now I need to get the query string from this url. I don;t wanna use request.META for getting query string. How ever I figured it out that there are two more ways to get the query string


  1. 使用urlparse
    使用urlparse.urlparse(url).query dats it

  1. Using urlparse Use urlparse.urlparse(url).query dats it

使用url encode
使用urlencode并将request.GET params字典传递给它,以获取它的字符串表示。

Using url encode Use urlencode and pass the request.GET params dictionary into it,to get the string representation of it....

哪个方式更好地获取查询字符串...?
我的一些同事说,urlencode是好多了,但我不满意wid有答案到目前为止,因为他们提到urlparse调用内部的urlencode。在这一点上我怀疑,我认为urlparse和urlencode是完全独立的。urlencode在urllib模块....请澄清这件事。

So which way is better to get the query string...? Some of my colleagues are saying that urlencode is much better , however I am not satisfied wid there answers so far..like they mentioned urlparse calls urlencode internally too..Even on this point I have doubt as I think urlparse and urlencode are entirely independent.as urlencode is in urllib module....please clarify this thing.

推荐答案

使用此类的GET参数

request.GET.urlencode()

这篇关于从python中的URL获取查询字符串的最佳方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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