我创建了一个新的Django(v.1.11)项目并使用python manage.py createsuperuser
创建了一个用户。我可以使用此用户帐户登录localhost:8888/admin
上的管理部分。但是,我不能做任何其他事情:每当我触发POST请求而不是登录页面时,我收到以下错误:
/ admin /...
上的TypeError
slice indices must be integers or None or have an __index__ method
(" ......"可以替换为例如auth/group/add/
),但此行为是一般的,不是特定于此请求
以下回溯表明从页面解析CSRF令牌存在问题,但除了管理员之外,我在我的应用程序中的其他页面上没有出现此类问题。
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
任何想法可能是什么问题?提前谢谢。
答案 0 :(得分:1)
发现问题。
对于将来的参考,问题是项目设置中的键DATA_UPLOAD_MAX_MEMORY_SIZE
具有浮点值(10e6
是Python中易于忽略的浮点数)。它必须是整数。