如何避免“超过GET / POST参数的数量”错误? [英] How to avoid "The number of GET/POST parameters exceeded" error?

查看:549
本文介绍了如何避免“超过GET / POST参数的数量”错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的Django网站上创建了一个自定义管理页面,其中只有管理员将被允许,并且能够更改对象及其属性。
对象的数量非常多(精确到9220),并且在管理页面上有相同数量的输入字段作为该模型中的对象。

I have created a custom admin page on my Django website, Where only administrators will be allowed and will be able to change objects and their attributes. The amount of objects is a lot (9220 exactly) and on admin page there are equal amounts of input fields as objects in that model.

这是代码:

This is the code:

<form action="{% url 'Home:AdminPrices' %}" id="mainForm" method="post">
{% csrf_token %}
{% for item in prices %}
    <ul class="row" style="width: 100%;padding: 0;background-color: white;height: 100px;display: flex;justify-content: left;white-space: nowrap;margin-bottom: 0;margin-top: 0;">
        <div style="width: 33.333333333333336%;background-color: white;display:  block;color: black;font-size: 0.8em;white-space: nowrap;text-align: center;font-family: 'Lato';padding-top: 25px;">{{ item.hashname }}</div>
        <div style="width: 33.333333333333336%;background-color: white;display:  block;color: black;font-size: 1.2em;text-align: center;font-family: 'Lato';padding-top: 25px;">{{ item.sug }}</div>
        <div style="width: 33.333333333333336%;background-color: white;display:  block;color: black;font-size: 1.2em;text-align: center;font-family: 'Lato';"><input type="number" value="{{ item.actual }}" name="prices_{{ item.actual }}" style="width: 100%;height: 100%;padding-bottom: 25px;background-color: white;border: 0;color: black;font-size: 1.2em;text-align: center;font-family: 'Lato';"></input></div>
    </ul>
{% endfor %}
    <input type="submit" id="mainSubmit" style="display: none;" name="submitPrices"></input>
</form>
<div onclick="document.getElementById('mainForm').submit();" style="background-color: black;border-radius: 5px;position: fixed;display: block;height: 50px;width: 200px;bottom: 0;left:0;right:0;margin: 0 auto;color: white;font-size: 1.5em;text-align: center;padding-top: 12.5px;cursor: pointer;">Submit</div>

按下提交按钮后,网站崩溃并提示出现此错误:

Once submit button is pressed, Website crashes and prompts out this error:


2017-06-25 10:05:53,158:GET / POST参数的数量超过
settings.DATA_UPLOAD_MAX_NUMBER_FIELDS。 2017-06-25 10:05:53,860:错误
运行WSGI应用程序2017-06-25 10:05:53,934:TooManyFieldsSent:
GET / POST参数的数量超过
设置。 DATA_UPLOAD_MAX_NUMBER_FIELDS。 2017-06-25 10:05:53,934:

文件
/home/Monsons/Tonskins/Selement/senv/local/lib/python2.7/site-packages/django/core /handlers/wsgi.py,
第170行,通话 2017-06-25 10:05:53,935:response =
self.get_response(request)2017-06 -25 10:05:53,935:2017-06-25
10:05:53,935:File
/home/Monsons/Tonskins/Selement/senv/local/lib/python2.7/site- packages / django / core / handlers / base.py,
line 124,in get_response 2017-06-25 10:05:53,935:response =
self._middleware_chain(request)2017-06-25 10:05:53,936:2017-06-25
10:05:53,936:File
/home/Monsons/Tonskins/Selement/senv/local/lib/python2.7/site-packages/ django / core / handlers / exception.py,
第41行,内部2017-06-25 10:05:53,936:response =
response_for_exception(request,exc)2017-06-25 10: 05:53,936:
2017-06-25 10:05:53,936:File
/home/Monsons/Tonskins/Selement/senv/local/lib/python2.7/site-packages/djang o / core / handlers / exception.py,
第76行,in response_for_exception 2017-06-25 10:05:53,937:

response = debug.technical_500_response(request,* sys.exc_info (),
status_code = 400)2017-06-25 10:05:53,937:2017-06-25 10:05:53,937:

文件
/ home / MTonskins /Tonskins/Selement/senv/local/lib/python2.7/site-packages/django/views/debug.py,
line 84,in technical_500_response 2017-06-25 10:05:53,937:html =
reporter.get_traceback_html()2017-06-25 10:05:53,937:2017-06-25
10:05:53,937:File
/ home / MTonskins / Tonskins / Selement / senv / local / lib / python2.7 / site-packages / django / views / debug.py,
line 316,in get_traceback_html 2017-06-25 10:05:53,938:c =
上下文(self.get_traceback_data(),use_l10n = False)2017-06-25
10:05:53,938:2017-06-25 10:05:53,938:File
/ home / MTonskins / Tonskins / Selement / senv / local / lib / python2.7 / site-packages / django / views / debug.py,
line 293,in get_traceback_data 2017- 06-25 10:05:53,938:

'filtered_POST':self.filter.get_post_parameters(self.request),
2017-06-25 10:05:53,938:2017-06- 25 10:05:53,938:File
/home/Monsons/Tonskins/Selement/senv/local/lib/python2.7/site-packages/django/views/debug.py,
line 167,in get_post_parameters 2017-06-25 10:05:53,938:return
request.POST 2017-06-25 10:05:53,938:2017-06-25 10:05:53,939:File
/home/Monsons/Tonskins/Selement/senv/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py,
line 128,in _get_post 2017-06-25 10 :05:53,939:

self._load_post_and_files()2017-06-25 10:05:53,939:2017-06-25
10:05:53,939:File
/ home / MTonskins / Tonskins / Selement / senv / local / lib / python2.7 / site-packages / django / http / request.py,
第311行,在_load_post_and_files 2017-06-25 10:05:53,939 :

self._post,self._files = QueryDict(self.body,
encoding = self._encoding),MultiValueDict()2017-06-25 10:05:53,939:
2017-06-25 10:05:53,940:File
/home/Monsons/Tonskins/Selement/senv/local/lib/python2.7/site-packages/django/http/request。 py,
第397行,在 init 中2017-06-25 10:05:53,940:关键值
中的值限制_parse_qsl(query_string,** parse_qsl_kwargs):2017- 06-25
10:05:53,940:2017-06-25 10:05:53,940:File
/home/Monsons/Tonskins/Selement/senv/local/lib/python2.7/site -packages / django / utils / http.py,
line 350,in limited_pa​​rse_qsl 2017-06-25 10:05:53,940:'GET / POST参数的
数量超过了

2017-06-25 10:05:53,158: The number of GET/POST parameters exceeded settings.DATA_UPLOAD_MAX_NUMBER_FIELDS. 2017-06-25 10:05:53,860: Error running WSGI application 2017-06-25 10:05:53,934: TooManyFieldsSent: The number of GET/POST parameters exceeded settings.DATA_UPLOAD_MAX_NUMBER_FIELDS. 2017-06-25 10:05:53,934:
File "/home/MTonskins/Tonskins/Selement/senv/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 170, in call 2017-06-25 10:05:53,935: response = self.get_response(request) 2017-06-25 10:05:53,935: 2017-06-25 10:05:53,935: File "/home/MTonskins/Tonskins/Selement/senv/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 124, in get_response 2017-06-25 10:05:53,935: response = self._middleware_chain(request) 2017-06-25 10:05:53,936: 2017-06-25 10:05:53,936: File "/home/MTonskins/Tonskins/Selement/senv/local/lib/python2.7/site-packages/django/core/handlers/exception.py", line 41, in inner 2017-06-25 10:05:53,936: response = response_for_exception(request, exc) 2017-06-25 10:05:53,936: 2017-06-25 10:05:53,936: File "/home/MTonskins/Tonskins/Selement/senv/local/lib/python2.7/site-packages/django/core/handlers/exception.py", line 76, in response_for_exception 2017-06-25 10:05:53,937:
response = debug.technical_500_response(request, *sys.exc_info(), status_code=400) 2017-06-25 10:05:53,937: 2017-06-25 10:05:53,937:
File "/home/MTonskins/Tonskins/Selement/senv/local/lib/python2.7/site-packages/django/views/debug.py", line 84, in technical_500_response 2017-06-25 10:05:53,937: html = reporter.get_traceback_html() 2017-06-25 10:05:53,937: 2017-06-25 10:05:53,937: File "/home/MTonskins/Tonskins/Selement/senv/local/lib/python2.7/site-packages/django/views/debug.py", line 316, in get_traceback_html 2017-06-25 10:05:53,938: c = Context(self.get_traceback_data(), use_l10n=False) 2017-06-25 10:05:53,938: 2017-06-25 10:05:53,938: File "/home/MTonskins/Tonskins/Selement/senv/local/lib/python2.7/site-packages/django/views/debug.py", line 293, in get_traceback_data 2017-06-25 10:05:53,938:
'filtered_POST': self.filter.get_post_parameters(self.request), 2017-06-25 10:05:53,938: 2017-06-25 10:05:53,938: File "/home/MTonskins/Tonskins/Selement/senv/local/lib/python2.7/site-packages/django/views/debug.py", line 167, in get_post_parameters 2017-06-25 10:05:53,938: return request.POST 2017-06-25 10:05:53,938: 2017-06-25 10:05:53,939: File "/home/MTonskins/Tonskins/Selement/senv/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 128, in _get_post 2017-06-25 10:05:53,939:
self._load_post_and_files() 2017-06-25 10:05:53,939: 2017-06-25 10:05:53,939: File "/home/MTonskins/Tonskins/Selement/senv/local/lib/python2.7/site-packages/django/http/request.py", line 311, in _load_post_and_files 2017-06-25 10:05:53,939:
self._post, self._files = QueryDict(self.body, encoding=self._encoding), MultiValueDict() 2017-06-25 10:05:53,939: 2017-06-25 10:05:53,940: File "/home/MTonskins/Tonskins/Selement/senv/local/lib/python2.7/site-packages/django/http/request.py", line 397, in init 2017-06-25 10:05:53,940: for key, value in limited_parse_qsl(query_string, **parse_qsl_kwargs): 2017-06-25 10:05:53,940: 2017-06-25 10:05:53,940: File "/home/MTonskins/Tonskins/Selement/senv/local/lib/python2.7/site-packages/django/utils/http.py", line 350, in limited_parse_qsl 2017-06-25 10:05:53,940: 'The number of GET/POST parameters exceeded

我不太确定我该如何避免它,我可以更改设置并专门为此视图设置不同的限制吗?或者我可以提交所有这些领域作为一个列表?如果不是,那么解决方案是什么?我可以在某些视图中指定 DATA_UPLOAD_MAX_NUMBER_FIELDS 设置吗?

I'm not quite sure how can i avoid it, Could i change the settings and set different limit specifically for this view? Or could i submit all these fields as one list? If not, Then what could be the solution? Can i specify DATA_UPLOAD_MAX_NUMBER_FIELDS setting to certain view? Thanks in advance.

推荐答案

Django的文档指出,设置不应该在设置以外的任何地方更改:

Django's documentation states that settings shouldn't be changed anywhere other than the settings:

https: //docs.djangoproject.com/en/1.11/topics/settings/#altering-settings-at-runtime

正如您所提到的,是否会增加设置中 DATA_UPLOAD_MAX_NUMBER_FIELDS 的大小。祝你好运!

The solution, as you mentioned, is it increase the size of DATA_UPLOAD_MAX_NUMBER_FIELDS in the settings. Good luck!

这篇关于如何避免“超过GET / POST参数的数量”错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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