我收到错误,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
我认为此错误是能够发送文件大小的限制,所以我在settings.py中添加了一个代码
DATA_UPLOAD_MAX_MEMORY_SIZE = 100000000
但错误无法解决。我将此页How to avoid "The number of GET/POST parameters exceeded" error?作为参考。我该如何解决这个问题?
答案 0 :(得分:16)
正如django的文档所说,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
答案 1 :(得分:4)
这发生在我尝试向后端发布大量列表值时。在我的情况下,我可以自由地将列表作为字符串发送,并且它起作用了。默认情况下,Django 会进行此检查以防止可疑活动 (SuspiciousOperation
)。
但是下面的设置也可以。
# to disable the check
DATA_UPLOAD_MAX_NUMBER_FIELDS = None
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