Extracting items out of a QueryDict

后端 未结 8 1225
清酒与你
清酒与你 2020-12-29 07:04

I have a querydict that looks like the following:


How would I extract

8条回答
  •  暖寄归人
    2020-12-29 07:38

    Maybe this doesn't fully apply to you. But when I searched for this, your question was the first Stackoverflow question.

    I just wanted to get basic POST data out in Django. So just using GET worked fine for me. As the others stated, it might be easier to better format whatever script is creating the query.

    Basically I have a AJAX doing a post towards Django, the POST looks a bit like this:

    params = name=somename&data=abcdefg
    http.send(params);
    

    then in my view.py, i did this :

    def somefuntion(request):
        if request.method == 'POST':
            log.info('POST applied')
            alldata=request.POST
            log.debug(alldata)
            data = alldata.get("data", "0")
            name = alldata.get("name", "0")
            log.info("POST name: " + name)
            log.info("POST data: " + data)
    

    The output of alldata was :

    
    

    and the get commands give :

    name: somename
    data: abcdefg
    

提交回复
热议问题