简体   繁体   English

从 Django 中的 POST 请求中获取值

[英]get value from POST request in Django

I want to get the value of the key 'result' but every time I'm trying to get it it becomes empty我想获得关键“结果”的价值,但每次我试图获得它时它都变成空的

if request.method == 'POST':
    result = request.POST

after printing the result打印结果后

as you can see there is something there but when I'm trying to print:如您所见,那里有一些东西,但是当我尝试打印时:

request.POST.get('result')

or要么

request.POST['result']

I'm getting an empty string我得到一个空字符串

Try this values = request.POST.getlist('result') , as request.POST.get('result') returns only the last element in array, it's '' in your case.试试这个values = request.POST.getlist('result') ,因为request.POST.get('result')只返回数组中的最后一个元素,在你的情况下它是'' Check this discussion.检查讨论。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM