getting tuples from http request.GET

109 views
Skip to first unread message

Sunil Sawant

unread,
Mar 4, 2015, 7:57:17 PM3/4/15
to django...@googlegroups.com
Hi Guys,

Pretty new to Django, but used it blindly and works wonders. But here is a situation I am blocked at now for a new project

I request.GET the following URL

https://mydesktop.com/validator?hostname1=host1.example.com,location1=ca,ip1=2.2.2.2,hostname2=host2.example.com,location2=wa,ip2=3.3.3.3

Am using request.GET I want to get the output in a tuple or hash form as:

[{host1.example.com:[ca,2.2.2.2]},{host2.example.com:[wa,3.3.3.3]}]



Once I have this data I can process it further.
Please help





Collin Anderson

unread,
Mar 6, 2015, 8:11:45 PM3/6/15
to django...@googlegroups.com
Hi,

Normally query arguments are separated by &. If you're able to send the data like this:


Then you could do something like:

data = []
i
= 0
while True:
    i
+= 1
   
try:
        data
.append((request.GET['hostname%s' % i], request.GET['location%s' % i], request.GET['ip%s' % i]))
   
except KeyError:
       
break

Collin

Sunil Sawant

unread,
Mar 7, 2015, 10:01:18 PM3/7/15
to django...@googlegroups.com
Thanks  Collin, you cut out the crap from from my code. Simple is beautiful :)

Jonathan Querubina

unread,
Mar 8, 2015, 8:19:35 AM3/8/15
to django...@googlegroups.com
You could use the same variable name on the querystring and call:

request.GET.getlist

For example, on a select multiple field ou checkbox

 John
Mobile & Web developer
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/fbdcea09-29e8-4765-9f36-47539a387dbb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages