相关疑难解决方法(0)

实现自定义用户模型时,creatuperuser会出现问题

我试图在Django 1.6中实现我自己的自定义用户模型,但我收到此错误.

Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/gabriel/.virtualenvs/hang_server/lib/python3.4/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "/Users/gabriel/.virtualenvs/hang_server/lib/python3.4/site-packages/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/gabriel/.virtualenvs/hang_server/lib/python3.4/site-packages/django/core/management/base.py", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/Users/gabriel/.virtualenvs/hang_server/lib/python3.4/site-packages/django/core/management/base.py", line 285, in execute
    output = self.handle(*args, **options)
  File "/Users/gabriel/.virtualenvs/hang_server/lib/python3.4/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 141, in handle
    self.UserModel._default_manager.db_manager(database).create_superuser(**user_data)
TypeError: create_superuser() missing 1 required positional argument: 'email'
Run Code Online (Sandbox Code Playgroud)

这是我的UserManager

class UserManager(BaseUserManager):

  def _create_user(self, username, email, password, is_staff, is_superuser, **extra_fields):
    now = timezone.now()
    email = self.normalize_email(email)
    user = …
Run Code Online (Sandbox Code Playgroud)

python django django-models django-users

9
推荐指数
1
解决办法
7582
查看次数

类型错误:create_superuser() 缺少 3 个必需的位置参数:

当我尝试使用终端创建新的超级用户时出现以下错误。

TypeError: create_superuser() missing 3 required positional arguments: 'first_name', 'last_name', and 'location'
Run Code Online (Sandbox Code Playgroud)

我在下面的评论中关注了另一个 stackoverflow 页面。在该页面中,它坚持创建一个 create_superuser 函数,但user.save(using=self._db) 此代码仍有错误,

如何使用“first_name”、“last_name”和“location”而不向它们提供任何默认值。

first_name 、 last_name 和 location 是 max_length = 30 的 CharField,并且可以有空白值。

在此自定义用户模型中,用户名被替换为 mobile_no,使其在 User 类中具有唯一性。

模型.py

from django.db import models
from django.contrib.auth.models import (
        AbstractBaseUser, BaseUserManager,PermissionsMixin
    )
class UserManager(BaseUserManager):
    # All required field must be passed below as argument
    def create_user(self, mobile_no, role, email, first_name, last_name, location, password=None, is_active=True,is_staff=False, is_admin= False):
        if not mobile_no:
            raise ValueError("User must have an Mobile …
Run Code Online (Sandbox Code Playgroud)

python django typeerror django-custom-manager django-custom-user

1
推荐指数
1
解决办法
3604
查看次数