how to obtain all values of a multi-valued key from Django's request.GET QueryDict

后端 未结 7 967
花落未央
花落未央 2021-02-07 04:11

The Django docs say at http://docs.djangoproject.com/en/dev/ref/request-response/#django.http.QueryDict.iteritems thatQueryDict.iteritems() uses the same last-value

相关标签:
7条回答
  • 2021-02-07 04:44

    you can cast the querydict into a dictionary

    map(int,dict(request.GET)["status"])
    
    0 讨论(0)
  • 2021-02-07 04:47

    There is a useful function in django http utils you can use:

    >>> from django.utils.http import urlencode
    >>> print(urlencode({"tag": [1, 2, 3], "sentence":2}, doseq=True))
    
    'tag=1&tag=2&tag=3&sentence=2'
    
    0 讨论(0)
  • 2021-02-07 04:51

    I believe QueryDict.urlencode achieves your desired outcome if all you want to do is print out the QueryDict then just

    print request.GET.urlencode()
    

    should do the trick. Let me know if you were trying to do something else and I'll try to help!

    0 讨论(0)
  • 2021-02-07 04:53
    request.GET.getlist('status')
    
    0 讨论(0)
  • 2021-02-07 05:02
    request.META['QUERY_STRING']
    

    will give the complete query string

    or if you want to get the list of values for a given key ex: list of values for status then

    request.GET.getlist('status')
    
    0 讨论(0)
  • 2021-02-07 05:02

    It's easy! Just print(dict(request.GET))

    0 讨论(0)
提交回复
热议问题