I created a new Django (v. 1.11) project and using python manage.py createsuperuser I created a user. I can log in to the admin section on localhost:8888/admin with this user account. However, I cannot do anything else: whenever I trigger a POST request other than the login page, I get the following error:
TypeError at /admin/...
slice indices must be integers or None or have an __index__ method
("..." can be replaced for example by auth/group/add/), but this behavior is general, not specific to this request
The following traceback suggests problem with parsing the CSRF token from the page, but I didn't have such issues on other pages within my application apart from admin.
Traceback:
File "/usr/local/lib/python2.7/site-packages/django/core/handlers/exception.py" in inner
41. response = get_response(request)
File "/usr/local/lib/python2.7/site-packages/django/core/handlers/base.py" in _get_response
178. response = middleware_method(request, callback, callback_args, callback_kwargs)
File "/usr/local/lib/python2.7/site-packages/django/middleware/csrf.py" in process_view
298. request_csrf_token = request.POST.get('csrfmiddlewaretoken', '')
File "/usr/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py" in _get_post
126. self._load_post_and_files()
File "/usr/local/lib/python2.7/site-packages/django/http/request.py" in _load_post_and_files
299. self._post, self._files = self.parse_file_upload(self.META, data)
File "/usr/local/lib/python2.7/site-packages/django/http/request.py" in parse_file_upload
258. return parser.parse()
File "/usr/local/lib/python2.7/site-packages/django/http/multipartparser.py" in parse
198. data = field_stream.read(size=read_size)
File "/usr/local/lib/python2.7/site-packages/django/http/multipartparser.py" in read
369. out = b''.join(parts())
File "/usr/local/lib/python2.7/site-packages/django/http/multipartparser.py" in parts
364. emitting = chunk[:remaining]
Exception Type: TypeError at /admin/auth/group/add/
Exception Value: slice indices must be integers or None or have an __index__ method
Any ideas what could be the problem? Thanks in advance.
Found the problem.
For the future reference, the problem was the key DATA_UPLOAD_MAX_MEMORY_SIZE in the project settings having a floating point value (10e6 is an easy-to-overlook float in Python). It has to be an integer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With