G
G
GiperScriper2014-02-18 10:42:22
Django
GiperScriper, 2014-02-18 10:42:22

How to implement query string parsing in Python (Django)?

Query string:

main.php?location=%D0%E0%E7%E4%EE%F0%FB&page=04rent&way=1&filtr=1

location = request.GET.get('location') # need to get the string '%D0%E0%E7%E4%EE%F0%FB', how can I implement this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
U
un1t, 2014-02-18
@GiperScriper

You have a string in cp1251, there may be problems with this.

In [1]: import urllib
In [3]: print urllib.unquote('%D0%E0%E7%E4%EE%F0%FB')
������
In [4]: print urllib.unquote('%D0%E0%E7%E4%EE%F0%FB').decode('cp1251')
Раздоры

M
MagNet, 2014-02-18
@MagNet

Or:

from django.http import QueryDict
x = QueryDict('location=%D0%E0%E7%E4%EE%F0%FB&page=04rent&way=1&filtr=1')
x.get('location')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question