0

電子メールを主キーとしてカスタム ユーザーを実装します。django rest と django-rest-auth をインストールすると、以下のエラーが発生します。

django がスローしているエラーは次のとおりです。

django.core.exceptions.FieldDoesNotExist: BaseUser has no field named 'username'

django-rest-auth がユーザー名を電子メールとして受け入れるオプションはありますか? シリアライザーとビューをオーバーライドしようとしていますが、これが最も安全なオプションかどうかはわかりません。

models.py

from django.db import models
from django.core.validators import RegexValidator
from django.core.urlresolvers import reverse
from django.utils import timezone
from django.utils.http import urlquote
from django.utils.translation import ugettext_lazy as _
from django.core.mail import send_mail
from django.core.files.storage import FileSystemStorage
from django.contrib.auth.models import (
    BaseUserManager, AbstractBaseUser, PermissionsMixin
)

class MyUserManager(BaseUserManager):
    def create_user(self, email, password=None):
        """
        Creates and saves a User with the given email, date of
        birth and password.
        """
        if not email:
            raise ValueError('Users must have an email address')

        user = self.model(
            email=self.normalize_email(email),
        )

        user.set_password(password)
        user.save(using=self._db)
        return user

    def create_superuser(self, email, password):
        """
        Creates and saves a superuser with the given email, date of
        birth and password.
        """
        user = self.create_user(email,
            password=password,
        )
        user.is_staff = True
        user.save(using=self._db)
        return user

# TODO: Password needs to be hashed
class BaseUser(AbstractBaseUser, PermissionsMixin):
    email = models.EmailField(
        verbose_name='email',
        max_length=255,
        unique=True,
    )

    first_name = models.CharField(blank=True, max_length=30)
    last_name = models.CharField(blank=True, max_length=50)
    mobile_regex = RegexValidator(regex=r'^\+?\d{9,15}$', message="Please enter a max of 10 digits :)")
    mobile = models.CharField(validators=[mobile_regex], max_length=10, blank=True)
    is_a_student = models.BooleanField(default=False)
    is_active = models.BooleanField(default=True)
    date_joined = models.DateTimeField(auto_now_add=True)
    is_staff = models.BooleanField(
        _('staff status'),
        default=False,
        help_text=_('Designates whether the user can log into this admin site.'),
    )

    objects = MyUserManager()

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = []

    class Meta:
        verbose_name = 'User'
        verbose_name_plural = 'Users'

    def is_student(self):
        return self.is_a_student

    def get_full_name(self):
        # The user is identified by their email address
        return self.email

    def get_short_name(self):
        # The user is identified by their email address
        return self.email

    def __str__(self):              # __unicode__ on Python 2
        return self.email

    def has_perm(self, perm, obj=None):
        "Does the user have a specific permission?"
        # Simplest possible answer: Yes, always
        return True

    def has_module_perms(self, app_label):
        "Does the user have permissions to view the app `app_label`?"
        # Simplest possible answer: Yes, always
        return True

    @property
    def is_admin(self):
        "Is the user a member of staff?"
        # Simplest possible answer: All admins are staff
        return self.is_staff

設定.py

"""
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
import dj_database_url
import logging
import copy
from django.utils.log import DEFAULT_LOGGING

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# Application definition
AUTH_USER_MODEL = 'user.BaseUser'

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',


    # Third Party Apps
    'coverage',
    'herokuapp',
    'localflavor',
    'django_extensions',
    'django_nose',
    'rest_framework',
    # 'rest_framework_swagger',
    'rest_framework_docs',



    # Third Party Authentication
    'rest_framework.authtoken',
    'rest_auth',
    'allauth',
    'allauth.account',
    'rest_auth.registration',

    # Local Apps
    'user',
    'student',
    'school',
    'employer',
    'job'
)

#Rest_Framework admin config
#Only uncomment if API is viewable for admins
"""
REST_FRAMEWORK = {
    'DEFAULT_PERMISSION_CLASSES': ('rest_framework.permissions.IsAdminUser',),
    'PAGE_SIZE': 10
}
"""
ACCOUNT_UNIQUE_EMAIL = True
ACCOUNT_USER_MODEL_USERNAME_FIELD = None
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_USERNAME_REQUIRED = False
ACCOUNT_AUTHENTICATION_METHOD = 'email'



MIDDLEWARE_CLASSES = (
    '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',
    'django.middleware.security.SecurityMiddleware',
)

ROOT_URLCONF = 'student_job.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

INTERNAL_IPS = '127.0.0.1'
WSGI_APPLICATION = 'student_job.wsgi.application'
DJANGO_WYSIWYG_FLAVOR = "ckeditor"

rest_swagger によるトレースバック

(univjobs-back) mariacarmenjavelona@Marias-MacBook-Pro ~/Desktop/univjobs-back/student_job (feature/react_redux●)$ ./manage.py runserver_plus
/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/django/core/management/base.py:265: RemovedInDjango110Warning: OptionParser usage for Django management commands is deprecated, use ArgumentParser instead
  RemovedInDjango110Warning)

 * Running on http://127.0.0.1:8000/ (Press CTRL+C to quit)
 * Restarting with stat
/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/django/core/management/base.py:265: RemovedInDjango110Warning: OptionParser usage for Django management commands is deprecated, use ArgumentParser instead
  RemovedInDjango110Warning)

Performing system checks...

System check identified no issues (0 silenced).

Django version 1.9.4, using settings 'student_job.settings'
Development server is running at http://127.0.0.1:8000/
Using the Werkzeug debugger (http://werkzeug.pocoo.org/)
Quit the server with CONTROL-C.
 * Debugger is active!
 * Debugger pin code: 215-984-059
 * Debugger is active!
 * Debugger pin code: 201-308-245
/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/django/template/loader.py:97: RemovedInDjango110Warning: render() must be called with a dict, not a RequestContext.
  return template.render(context, request)

127.0.0.1 - - [09/Mar/2016 20:34:05] "GET /docs/ HTTP/1.1" 200 -
127.0.0.1 - - [09/Mar/2016 20:34:05] "GET /static/rest_framework_swagger/css/highlight.default.css HTTP/1.1" 304 -
127.0.0.1 - - [09/Mar/2016 20:34:05] "GET /static/rest_framework_swagger/css/atelier-dune.light.css HTTP/1.1" 304 -
127.0.0.1 - - [09/Mar/2016 20:34:05] "GET /static/rest_framework_swagger/css/rest_framework_swagger.css HTTP/1.1" 304 -
127.0.0.1 - - [09/Mar/2016 20:34:05] "GET /static/rest_framework_swagger/css/screen.css HTTP/1.1" 304 -
127.0.0.1 - - [09/Mar/2016 20:34:05] "GET /static/rest_framework_swagger/images/wordnik_api.png HTTP/1.1" 304 -
127.0.0.1 - - [09/Mar/2016 20:34:05] "GET /static/rest_framework_swagger/lib/shred.bundle.js HTTP/1.1" 304 -
127.0.0.1 - - [09/Mar/2016 20:34:05] "GET /static/rest_framework_swagger/lib/jquery-1.8.0.min.js HTTP/1.1" 304 -
127.0.0.1 - - [09/Mar/2016 20:34:05] "GET /static/rest_framework_swagger/lib/jquery.slideto.min.js HTTP/1.1" 304 -
127.0.0.1 - - [09/Mar/2016 20:34:05] "GET /static/rest_framework_swagger/lib/jquery.wiggle.min.js HTTP/1.1" 304 -
127.0.0.1 - - [09/Mar/2016 20:34:05] "GET /static/rest_framework_swagger/lib/jquery.ba-bbq.min.js HTTP/1.1" 304 -
127.0.0.1 - - [09/Mar/2016 20:34:05] "GET /static/rest_framework_swagger/lib/jquery.cookie.js HTTP/1.1" 304 -
127.0.0.1 - - [09/Mar/2016 20:34:05] "GET /static/rest_framework_swagger/lib/handlebars-1.0.0.js HTTP/1.1" 304 -
127.0.0.1 - - [09/Mar/2016 20:34:05] "GET /static/rest_framework_swagger/lib/underscore-min.js HTTP/1.1" 304 -
127.0.0.1 - - [09/Mar/2016 20:34:05] "GET /static/rest_framework_swagger/lib/swagger.js HTTP/1.1" 304 -
127.0.0.1 - - [09/Mar/2016 20:34:05] "GET /static/rest_framework_swagger/swagger-ui.min.js HTTP/1.1" 304 -
127.0.0.1 - - [09/Mar/2016 20:34:05] "GET /static/rest_framework_swagger/lib/highlight.8.0.pack.js HTTP/1.1" 304 -
127.0.0.1 - - [09/Mar/2016 20:34:05] "GET /static/rest_framework_swagger/lib/backbone-min.js HTTP/1.1" 304 -
127.0.0.1 - - [09/Mar/2016 20:34:05] "GET /docs/api-docs/ HTTP/1.1" 200 -
127.0.0.1 - - [09/Mar/2016 20:34:05] "GET /docs/api-docs/ HTTP/1.1" 200 -
127.0.0.1 - - [09/Mar/2016 20:34:05] "GET /docs/api-docs/rest_auth/login HTTP/1.1" 200 -
127.0.0.1 - - [09/Mar/2016 20:34:05] "GET /docs/api-docs/rest_auth/logout HTTP/1.1" 200 -
127.0.0.1 - - [09/Mar/2016 20:34:05] "GET /docs/api-docs/rest_auth/password HTTP/1.1" 200 -
127.0.0.1 - - [09/Mar/2016 20:34:05] "GET /docs/api-docs/rest_auth/register HTTP/1.1" 200 -
Internal Server Error: /docs/api-docs/rest_auth/user
Traceback (most recent call last):
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/django/core/handlers/base.py", line 149, in get_response
    response = self.process_exception_by_middleware(e, request)
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/django/core/handlers/base.py", line 147, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
    return view_func(*args, **kwargs)
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/django/views/generic/base.py", line 68, in view
    return self.dispatch(request, *args, **kwargs)
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/rest_framework/views.py", line 466, in dispatch
    response = self.handle_exception(exc)
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/rest_framework/views.py", line 463, in dispatch
    response = handler(request, *args, **kwargs)
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/rest_framework_swagger/views.py", line 163, in get
    'apis': generator.generate(apis),
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/rest_framework_swagger/docgenerator.py", line 52, in generate
    'operations': self.get_operations(api, apis),
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/rest_framework_swagger/docgenerator.py", line 106, in get_operations
    inspector=method_introspector)
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/rest_framework_swagger/introspectors.py", line 1137, in discover_parameters
    method_params = inspector.get_parameters()
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/rest_framework_swagger/introspectors.py", line 309, in get_parameters
    form_params = self.build_form_parameters()
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/rest_framework_swagger/introspectors.py", line 433, in build_form_parameters
    fields = serializer().get_fields()
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/rest_framework/serializers.py", line 939, in get_fields
    field_name, info, model, depth
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/rest_framework/serializers.py", line 1076, in build_field
    return self.build_unknown_field(field_name, model_class)
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/rest_framework/serializers.py", line 1182, in build_unknown_field
    (field_name, model_class.__name__)
django.core.exceptions.ImproperlyConfigured: Field name `username` is not valid for model `BaseUser`.
127.0.0.1 - - [09/Mar/2016 20:34:05] "GET /docs/api-docs/rest_auth/user HTTP/1.1" 500 -
Traceback (most recent call last):
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/django/contrib/staticfiles/handlers.py", line 63, in __call__
    return self.application(environ, start_response)
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/dj_static.py", line 83, in __call__
    return self.application(environ, start_response)
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/django/core/handlers/wsgi.py", line 177, in __call__
    response = self.get_response(request)
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/django/core/handlers/base.py", line 230, in get_response
    response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/django/core/handlers/base.py", line 289, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/django_extensions/management/technical_response.py", line 5, in null_technical_500_response
    six.reraise(exc_type, exc_value, tb)
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/six.py", line 659, in reraise
    raise value
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/django/core/handlers/base.py", line 149, in get_response
    response = self.process_exception_by_middleware(e, request)
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/django/core/handlers/base.py", line 147, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
    return view_func(*args, **kwargs)
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/django/views/generic/base.py", line 68, in view
    return self.dispatch(request, *args, **kwargs)
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/rest_framework/views.py", line 466, in dispatch
    response = self.handle_exception(exc)
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/rest_framework/views.py", line 463, in dispatch
    response = handler(request, *args, **kwargs)
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/rest_framework_swagger/views.py", line 163, in get
    'apis': generator.generate(apis),
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/rest_framework_swagger/docgenerator.py", line 52, in generate
    'operations': self.get_operations(api, apis),
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/rest_framework_swagger/docgenerator.py", line 106, in get_operations
    inspector=method_introspector)
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/rest_framework_swagger/introspectors.py", line 1137, in discover_parameters
    method_params = inspector.get_parameters()
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/rest_framework_swagger/introspectors.py", line 309, in get_parameters
    form_params = self.build_form_parameters()
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/rest_framework_swagger/introspectors.py", line 433, in build_form_parameters
    fields = serializer().get_fields()
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/rest_framework/serializers.py", line 939, in get_fields
    field_name, info, model, depth
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/rest_framework/serializers.py", line 1076, in build_field
    return self.build_unknown_field(field_name, model_class)
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/rest_framework/serializers.py", line 1182, in build_unknown_field
    (field_name, model_class.__name__)
django.core.exceptions.ImproperlyConfigured: Field name `username` is not valid for model `BaseUser`.
127.0.0.1 - - [09/Mar/2016 20:34:05] "GET /docs/api-docs/rest_auth/login HTTP/1.1" 200 -
127.0.0.1 - - [09/Mar/2016 20:34:05] "GET /docs/api-docs/rest_auth/logout HTTP/1.1" 200 -
127.0.0.1 - - [09/Mar/2016 20:34:05] "GET /docs/api-docs/rest_auth/password HTTP/1.1" 200 -
127.0.0.1 - - [09/Mar/2016 20:34:05] "GET /docs/api-docs/rest_auth/register HTTP/1.1" 200 -
Internal Server Error: /docs/api-docs/rest_auth/user
Traceback (most recent call last):
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/django/core/handlers/base.py", line 149, in get_response
    response = self.process_exception_by_middleware(e, request)
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/django/core/handlers/base.py", line 147, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
    return view_func(*args, **kwargs)
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/django/views/generic/base.py", line 68, in view
    return self.dispatch(request, *args, **kwargs)
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/rest_framework/views.py", line 466, in dispatch
    response = self.handle_exception(exc)
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/rest_framework/views.py", line 463, in dispatch
    response = handler(request, *args, **kwargs)
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/rest_framework_swagger/views.py", line 163, in get
    'apis': generator.generate(apis),
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/rest_framework_swagger/docgenerator.py", line 52, in generate
    'operations': self.get_operations(api, apis),
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/rest_framework_swagger/docgenerator.py", line 106, in get_operations
    inspector=method_introspector)
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/rest_framework_swagger/introspectors.py", line 1137, in discover_parameters
    method_params = inspector.get_parameters()
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/rest_framework_swagger/introspectors.py", line 309, in get_parameters
    form_params = self.build_form_parameters()
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/rest_framework_swagger/introspectors.py", line 433, in build_form_parameters
    fields = serializer().get_fields()
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/rest_framework/serializers.py", line 939, in get_fields
    field_name, info, model, depth
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/rest_framework/serializers.py", line 1076, in build_field
    return self.build_unknown_field(field_name, model_class)
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/rest_framework/serializers.py", line 1182, in build_unknown_field
    (field_name, model_class.__name__)
django.core.exceptions.ImproperlyConfigured: Field name `username` is not valid for model `BaseUser`.
127.0.0.1 - - [09/Mar/2016 20:34:05] "GET /docs/api-docs/rest_auth/user HTTP/1.1" 500 -
Traceback (most recent call last):
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/django/contrib/staticfiles/handlers.py", line 63, in __call__
    return self.application(environ, start_response)
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/dj_static.py", line 83, in __call__
    return self.application(environ, start_response)
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/django/core/handlers/wsgi.py", line 177, in __call__
    response = self.get_response(request)
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/django/core/handlers/base.py", line 230, in get_response
    response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/django/core/handlers/base.py", line 289, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/django_extensions/management/technical_response.py", line 5, in null_technical_500_response
    six.reraise(exc_type, exc_value, tb)
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/six.py", line 659, in reraise
    raise value
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/django/core/handlers/base.py", line 149, in get_response
    response = self.process_exception_by_middleware(e, request)
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/django/core/handlers/base.py", line 147, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
    return view_func(*args, **kwargs)
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/django/views/generic/base.py", line 68, in view
    return self.dispatch(request, *args, **kwargs)
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/rest_framework/views.py", line 466, in dispatch
    response = self.handle_exception(exc)
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/rest_framework/views.py", line 463, in dispatch
    response = handler(request, *args, **kwargs)
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/rest_framework_swagger/views.py", line 163, in get
    'apis': generator.generate(apis),
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/rest_framework_swagger/docgenerator.py", line 52, in generate
    'operations': self.get_operations(api, apis),
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/rest_framework_swagger/docgenerator.py", line 106, in get_operations
    inspector=method_introspector)
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/rest_framework_swagger/introspectors.py", line 1137, in discover_parameters
    method_params = inspector.get_parameters()
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/rest_framework_swagger/introspectors.py", line 309, in get_parameters
    form_params = self.build_form_parameters()
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/rest_framework_swagger/introspectors.py", line 433, in build_form_parameters
    fields = serializer().get_fields()
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/rest_framework/serializers.py", line 939, in get_fields
    field_name, info, model, depth
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/rest_framework/serializers.py", line 1076, in build_field
    return self.build_unknown_field(field_name, model_class)
  File "/Users/mariacarmenjavelona/.virtualenvs/univjobs-back/lib/python3.5/site-packages/rest_framework/serializers.py", line 1182, in build_unknown_field
    (field_name, model_class.__name__)
django.core.exceptions.ImproperlyConfigured: Field name `username` is not valid for model `BaseUser`.
4

4 に答える 4

1

バージョン 0.6.0 を使用すると、その問題が発生します。プロジェクト環境を Django-Rest-Auth のバージョン 0.7.0 に更新し、カスタム ユーザー モデルで ACCOUNT_USER_MODEL_USERNAME_FIELD パラメータを設定してください。

それでも問題が解決しない場合は、この問題を繰り返す方法を教えてください。

于 2016-03-08T02:13:19.940 に答える
0

お使いの django バージョンは、auth パッケージでサポートされていません。

django 1.9.4 バージョン (最新バージョン) を使用してください。django をアップグレードしてください。

于 2016-03-08T13:22:12.930 に答える