Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can I get the values from the "GET" parameters as array?

I can get data from url like this.

http://127.0.0.1:8000/page/?key=003

I show output as Json. This is view.py

def page(request):

    key = request.GET['key']

    data=Device.objects.get(key=key)
    print(key)
   
    data = {
        "open": data.open,
        "close": data.close,
    }

    return JsonResponse(data, safe=False)

I try to get many value in same time like this

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

http://127.0.0.1:8000/page/?key=003&key=004

In terminal it show output like this.

[22/Mar/2022 15:19:22] "GET /page/?key=003&key004 HTTP/1.1" 200 64
003

The output show 003 only. Can I get the values from the "GET" parameters as array?

>Solution :

Yes, you can have more than one parameter with the same key. Just do this:

key = request.GET.getlist('key')

And you will get an array with the key values.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading