如何从Django中的请求获取所有发布数据? [英] How to Get all post data from a request in Django?

查看:32
本文介绍了如何从Django中的请求获取所有发布数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么办法可以从Django中的请求中获取所有表单名称吗?

Is there any way get all the form names from a request in Django ?

<input type="text" name="getrow">

HTML请求

def demoform(request):
    if request.method=="POST"
       inputtxt=request.POST.get("getrow")
       return HttpResponse(...)

上面的

我只能从我知道的 name 中获取,我需要获取django请求的所有名称,然后解析它并获取数据.

in the above I can get only from the name I know, what I need is to get all names of the django request and later parse it and get data.

推荐答案

尝试使用此方法:

def demoform(request):
    if request.method=="POST":
        inputtxt=request.POST['getrow']
        return HttpResponse(...)

但是,如果您需要打印动态POST数据,例如发送许多产品的信息,(我在2天前于"April 22,2018"发送),则需要尝试以下操作:

But if you need print a dynamic POST data, for example send the slug of many products, (i made it 2 days ago "April 22, 2018") you need try this:

for key, value in request.POST.items():
    print('Key: %s' % (key) ) 
    # print(f'Key: {key}') in Python >= 3.7
    print('Value %s' % (value) )
    # print(f'Value: {value}') in Python >= 3.7

这篇关于如何从Django中的请求获取所有发布数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆