I am working django and I want to fetch GET requests from url and want to delete couple of parameter and than save rest of in database as list.
For example, requested url is
localhost/test?a=A&b=B&c=C&d=D&e=E
I know how to get GET parameters in json format by simply doing
json.dumps(reqest.GET)
and when I print it out in template HttpResponse, I get
{"a":"A", "b":"B", "c":"C", "d":"D", "e":"E"}
what I want to do is I want to remove couple elements from it and create json. I want to remove by key "a" and "d". So my json should look like,
{"b":"B", "c":"C", "e":"E"}
Can anyone tell me how can I do it? I tried to look for list
, json
to list
etc and remove(), del element
etc method. Each time I was getting errors so can anyone help me?
Thank you for your time.
You can try something like this,
a = json.loads(json.dumps(request.GET))
del a['a']
del a['d']
return HttpResponse(json.dumps(a), content_type="application/json")
Let me know if helps... :D ;)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments