有没有办法从 Django 中的请求中获取所有表单名称?
<input type="text" name="getrow">
HTML请求
def demoform(request):
if request.method=="POST"
inputtxt=request.POST.get("getrow")
return HttpResponse(...)
在上面我只能从 name 获取我知道,我需要的是获取 django 请求的所有名称,然后解析它并获取数据。
请您参考如下方法:
尝试使用这个:
def demoform(request):
if request.method=="POST":
inputtxt=request.POST['getrow']
return HttpResponse(...)
但是如果你需要打印一个动态的 POST 数据,例如发送许多产品的 slug,(我在 2 天前“2018 年 4 月 22 日”制作的)你需要试试这个:
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
