我通过扩展Django的AbstractUser
定义了自定义用户模型。因此,当我尝试从djano管理页面创建用户时,会收到generator stopiteration
错误。下面是追溯。
Environment:
Request Method: POST
Request URL: http://127.0.0.1:8000/admin/users/user/add/
Django Version: 1.8
Python Version: 3.7.3
Installed Applications:
['posts.apps.PostsConfig',
'users.apps.UsersConfig',
'common.apps.CommonConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'crispy_forms']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Traceback:
File "/home/rohit/.virtualenvs/django-env/lib/python3.7/site-packages/django/core/handlers/base.py" in get_response
125. response = middleware_method(request, callback, callback_args, callback_kwargs)
File "/home/rohit/.virtualenvs/django-env/lib/python3.7/site-packages/django/middleware/csrf.py" in process_view
174. request_csrf_token = request.POST.get('csrfmiddlewaretoken', '')
File "/home/rohit/.virtualenvs/django-env/lib/python3.7/site-packages/django/core/handlers/wsgi.py" in _get_post
137. self._load_post_and_files()
File "/home/rohit/.virtualenvs/django-env/lib/python3.7/site-packages/django/http/request.py" in _load_post_and_files
260. self._post, self._files = self.parse_file_upload(self.META, data)
File "/home/rohit/.virtualenvs/django-env/lib/python3.7/site-packages/django/http/request.py" in parse_file_upload
225. return parser.parse()
File "/home/rohit/.virtualenvs/django-env/lib/python3.7/site-packages/django/http/multipartparser.py" in parse
149. for item_type, meta_data, field_stream in Parser(stream, self._boundary):
File "/home/rohit/.virtualenvs/django-env/lib/python3.7/site-packages/django/http/multipartparser.py" in __iter__
628. yield parse_boundary_stream(sub_stream, 1024)
File "/home/rohit/.virtualenvs/django-env/lib/python3.7/site-packages/django/http/multipartparser.py" in parse_boundary_stream
567. chunk = stream.read(max_header_size)
File "/home/rohit/.virtualenvs/django-env/lib/python3.7/site-packages/django/http/multipartparser.py" in read
337. out = b''.join(parts())
Exception Type: RuntimeError at /admin/users/user/add/
Exception Value: generator raised StopIteration
这仅在使用Django Admin创建用户时发生,否则从django shell运行就可以了。
这是我的“自定义用户”模型的样子
class User(AbstractUser):
description = models.TextField('profile summary', null=True, blank=True)
location = models.CharField('Location', max_length=50, null=True, blank=True)
class Meta:
verbose_name = 'CustomUser'
在settings.py
中,我更改了AUTH_USER_MODEL=users.User
。
那我在这里想念什么?
我使用django 2.2
进行了测试,并且相同的代码也可以正常工作,请再次确保我使用django 1.8
创建了一个全新的Django项目,并且扩展了User并得到了相同的错误。 / p>
这似乎发生在向Django admin注册的任何模型上,我创建了一个新模型,向Admin注册,然后尝试通过admin为此模型创建新记录,但失败,并出现上述相同错误。
因此,我认为这是django 1.8
的问题。
还有其他人也遇到过这个问题吗?