Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid "The number of GET/POST parameters exceeded" error?

Tags:

html

forms

django

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: 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

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.

like image 625
ShellRox Avatar asked Jun 25 '17 10:06

ShellRox


2 Answers

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

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

like image 198
FlipperPA Avatar answered Oct 06 '22 00:10

FlipperPA


in settings.py just increase "DATA_UPLOAD_MAX_NUMBER_FIELDS" value or disabled checking for this value , where the Default is 1000:

for example

# to increase value
DATA_UPLOAD_MAX_NUMBER_FIELDS = 102400

# to disabled check 
DATA_UPLOAD_MAX_NUMBER_FIELDS = None

check Django docs on the following url : https://docs.djangoproject.com/en/3.2/ref/settings/#data-upload-max-number-fields

I hope this helpful.

like image 34
K.A Avatar answered Oct 05 '22 23:10

K.A