代码之家  ›  专栏  ›  技术社区  ›  Laxmikant

Django自定义用户模型配置文件avtaar图像上载失败

  •  0
  • Laxmikant  · 技术社区  · 5 年前

    models.py

    class User(AbstractBaseUser, PermissionsMixin):
        email = models.EmailField(
            verbose_name=_('email address'), max_length=255, unique=True
        )
        # password field supplied by AbstractBaseUser
        # last_login field supplied by AbstractBaseUser
        salutation = models.CharField(_("Salutation"), max_length=10, blank=True)
        first_name = models.CharField(_('First name'), max_length=30, blank=True)
        middle_name = models.CharField(_('Middle name'), max_length=150, blank=True)
        last_name = models.CharField(_('Last name'), max_length=150, blank=True)
        gender = models.IntegerField(_("Gender"), blank=True, null=True)
        profile = models.ImageField(_("profile"), upload_to="profiles/", default="profiles/default/avtaar.jpg", blank=True, null=True) #<------------ This line causing the error 
        birth_date = models.DateField(_("Birth Date"), auto_now_add=False, null=True)
        blood_group = models.CharField(_("Blood Group"), max_length=50, blank=True, null=True)
        
        objects = UserManager()
        USERNAME_FIELD = 'email'
        REQUIRED_FIELDS = ['first_name', 'last_name']
    

    获取错误:

    Traceback (most recent call last):
      File "C:\Users\laxmikant\.virtualenvs\myproject-PblIhfcB\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
        response = get_response(request)
      File "C:\Users\laxmikant\.virtualenvs\myproject-PblIhfcB\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
        response = self.process_exception_by_middleware(e, request)
      File "C:\Users\laxmikant\.virtualenvs\myproject-PblIhfcB\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
        response = wrapped_callback(request, *callback_args, **callback_kwargs)
      File "C:\Users\laxmikant\.virtualenvs\myproject-PblIhfcB\lib\site-packages\django\contrib\admin\options.py", line 607, in wrapper
        return self.admin_site.admin_view(view)(*args, **kwargs)
      File "C:\Users\laxmikant\.virtualenvs\myproject-PblIhfcB\lib\site-packages\django\utils\decorators.py", line 130, in _wrapped_view
        response = view_func(request, *args, **kwargs)
      File "C:\Users\laxmikant\.virtualenvs\myproject-PblIhfcB\lib\site-packages\django\views\decorators\cache.py", line 44, in _wrapped_view_func
        response = view_func(request, *args, **kwargs)
      File "C:\Users\laxmikant\.virtualenvs\myproject-PblIhfcB\lib\site-packages\django\contrib\admin\sites.py", line 231, in inner
        return view(request, *args, **kwargs)
      File "C:\Users\laxmikant\.virtualenvs\myproject-PblIhfcB\lib\site-packages\django\contrib\admin\options.py", line 1641, in change_view
        return self.changeform_view(request, object_id, form_url, extra_context)
      File "C:\Users\laxmikant\.virtualenvs\myproject-PblIhfcB\lib\site-packages\django\utils\decorators.py", line 43, in _wrapper
        return bound_method(*args, **kwargs)
      File "C:\Users\laxmikant\.virtualenvs\myproject-PblIhfcB\lib\site-packages\django\utils\decorators.py", line 130, in _wrapped_view
        response = view_func(request, *args, **kwargs)
      File "C:\Users\laxmikant\.virtualenvs\myproject-PblIhfcB\lib\site-packages\django\contrib\admin\options.py", line 1522, in changeform_view
        return self._changeform_view(request, object_id, form_url, extra_context)
      File "C:\Users\laxmikant\.virtualenvs\myproject-PblIhfcB\lib\site-packages\django\contrib\admin\options.py", line 1565, in _changeform_view
        self.save_model(request, new_object, form, not add)
      File "C:\Users\laxmikant\.virtualenvs\myproject-PblIhfcB\lib\site-packages\django\contrib\admin\options.py", line 1081, in save_model
        obj.save()
      File "C:\Users\laxmikant\.virtualenvs\myproject-PblIhfcB\lib\site-packages\django\contrib\auth\base_user.py", line 66, in save
        super().save(*args, **kwargs)
      File "C:\Users\laxmikant\.virtualenvs\myproject-PblIhfcB\lib\site-packages\django\db\models\base.py", line 745, in save
        self.save_base(using=using, force_insert=force_insert,
      File "C:\Users\laxmikant\.virtualenvs\myproject-PblIhfcB\lib\site-packages\django\db\models\base.py", line 782, in save_base
        updated = self._save_table(
      File "C:\Users\laxmikant\.virtualenvs\myproject-PblIhfcB\lib\site-packages\django\db\models\base.py", line 861, in _save_table
        values = [(f, None, (getattr(self, f.attname) if raw else f.pre_save(self, False)))
      File "C:\Users\laxmikant\.virtualenvs\myproject-PblIhfcB\lib\site-packages\django\db\models\base.py", line 861, in <listcomp>
        values = [(f, None, (getattr(self, f.attname) if raw else f.pre_save(self, False)))
      File "C:\Users\laxmikant\.virtualenvs\myproject-PblIhfcB\lib\site-packages\django\db\models\fields\files.py", line 288, in pre_save
        file.save(file.name, file.file, save=False)
      File "C:\Users\laxmikant\.virtualenvs\myproject-PblIhfcB\lib\site-packages\django\db\models\fields\files.py", line 87, in save
        self.name = self.storage.save(name, content, max_length=self.field.max_length)
      File "C:\Users\laxmikant\.virtualenvs\myproject-PblIhfcB\lib\site-packages\django\core\files\storage.py", line 51, in save
        name = self.get_available_name(name, max_length=max_length)
      File "C:\Users\laxmikant\.virtualenvs\myproject-PblIhfcB\lib\site-packages\django\core\files\storage.py", line 82, in get_available_name
        while self.exists(name) or (max_length and len(name) > max_length):
      File "C:\Users\laxmikant\.virtualenvs\myproject-PblIhfcB\lib\site-packages\django\core\files\storage.py", line 311, in exists
        return os.path.exists(self.path(name))
      File "C:\Users\laxmikant\.virtualenvs\myproject-PblIhfcB\lib\site-packages\django\core\files\storage.py", line 324, in path
        return safe_join(self.location, name)
      File "C:\Users\laxmikant\.virtualenvs\myproject-PblIhfcB\lib\site-packages\django\utils\functional.py", line 48, in __get__
        res = instance.__dict__[self.name] = self.func(instance)
      File "C:\Users\laxmikant\.virtualenvs\myproject-PblIhfcB\lib\site-packages\django\core\files\storage.py", line 214, in location
        return os.path.abspath(self.base_location)
      File "C:\Users\laxmikant\.virtualenvs\myproject-PblIhfcB\lib\ntpath.py", line 543, in abspath
        path = os.fspath(path)
    
    Exception Type: TypeError at /db/core/user/1/change/
    Exception Value: expected str, bytes or os.PathLike object, not list
    

    不知道如何解决这个错误!PFA截图。 screenshot

    0 回复  |  直到 5 年前