我收到一个错误,GET/POST参数的数量超出了设置.DATA_UPLOAD_MAX_NUMBER_FIELDS.Error在/ api/upload上说TooManyFieldsSent GET/POST参数的数量超出了settings.DATA_UPLOAD_MAX_NUMBER_FIELDS.我在views.py中写道
def upload(request):
id, array = common(request)
if request.FILES:
file = request.FILES['req'].temporary_file_path()
else:
return HttpResponse('<h1>NG</h1>')
return HttpResponse('<h1>OK</h1>')
def common(request):
id = json_body.get("access", "0")
if id == "":
id = "0"
s = []
with open(ID_TXT, 'r') as f:
for line in f:
s += list(map(int, line.rstrip().split(',')[:-1]))
array = [s[i:i + 2] for i in range(0, len(s), 2)]
return id, array
Run Code Online (Sandbox Code Playgroud)
我认为这个错误是能够发送文件大小的限制,所以我在settings.py中添加了一个代码
DATA_UPLOAD_MAX_MEMORY_SIZE = 100000000
Run Code Online (Sandbox Code Playgroud)
但错误无法解决.我读了这个页面如何避免"超出GET/POST参数的数量"错误?作为参考.我该如何解决这个问题?
Yun*_*Luo 31
正如django的doc所说,DATA_UPLOAD_MAX_NUMBER_FIELDS的值是默认的1000,所以一旦你的表单包含的字段多于那个数字,你就会得到TooManyFields错误.
点击这里:https://docs.djangoproject.com/en/1.11/ref/settings/
所以解决方案很简单我认为,如果您的settings.py存在DATA_UPLOAD_MAX_NUMBER_FIELDS,则将其值更改为更高的值,或者如果不存在,则将其添加到settings.py:
DATA_UPLOAD_MAX_NUMBER_FIELDS = 10240 # higher than the count of fields
Run Code Online (Sandbox Code Playgroud)
当我尝试向后端发布一个巨大的列表值时发生了这种情况。在我的情况下,我可以自由地将列表作为字符串发送,并且它起作用了。Django 默认有这个检查来防止可疑活动(SuspiciousOperation)。
但是,以下设置也将起作用。
# to disable the check
DATA_UPLOAD_MAX_NUMBER_FIELDS = None
Run Code Online (Sandbox Code Playgroud)
You can set this to None to disable the check. Applications that are expected to receive an unusually large number of form fields should tune this setting.来自 Django 官方文档。https://docs.djangoproject.com/en/3.1/ref/settings/#data-upload-max-number-fields
| 归档时间: |
|
| 查看次数: |
10365 次 |
| 最近记录: |