django - Rest Framework Swagger: Error when implementing custom user without username field -


i have implemented custom user email primary key , removed username field. fine, when try launch swagger, error:

improperlyconfigured @ /api/v1/swagger/ field name username not valid model customuser.

here traceback rest_framework_swagger:

improperlyconfigured @ /api/v1/swagger/ field name `username` not valid model `customuser`.  request method: request url: http://localhost:8000/api/v1/swagger/ django version: 1.10.5 python executable: /users/ngm/.virtualenvs/venv/bin/python python version: 3.6.0 python path: ['/users/ngm/pycharmprojects/hou', '/library/frameworks/python.framework/versions/3.6/lib/python36.zip', '/library/frameworks/python.framework/versions/3.6/lib/python3.6', '/library/frameworks/python.framework/versions/3.6/lib/python3.6/lib-dynload', '/users/ngm/.virtualenvs/venv/lib/python3.6/site-packages', '/users/ngm/.virtualenvs/venv/lib/python3.6/site-packages/pip-7.1.0-py3.6.egg',] server time: fri, 7 apr 2017 08:53:44 +0000 installed applications: ['django.contrib.admin',  'django.contrib.auth',  'django.contrib.contenttypes',  'django.contrib.sessions',  'django.contrib.messages',  'django.contrib.staticfiles',  'rest_framework',  'api.apps.apiconfig',  'rest_framework.authtoken',  'rest_auth',  'django.contrib.sites',  'allauth',  'allauth.account',  'rest_auth.registration',  'allauth.socialaccount',  'allauth.socialaccount.providers.facebook',  'phonenumber_field',  'rest_framework_swagger'] 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.messages.middleware.messagemiddleware',  'django.middleware.clickjacking.xframeoptionsmiddleware']   traceback:    file "/users/ngm/.virtualenvs/venv/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner   39.             response = get_response(request)  file "/users/ngm/.virtualenvs/venv/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response   187.                 response = self.process_exception_by_middleware(e, request)  file "/users/ngm/.virtualenvs/venv/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response   185.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)  file "/users/ngm/.virtualenvs/venv/lib/python3.6/site-packages/django/views/decorators/csrf.py" in wrapped_view   58.         return view_func(*args, **kwargs)  file "/users/ngm/.virtualenvs/venv/lib/python3.6/site-packages/django/views/generic/base.py" in view   68.             return self.dispatch(request, *args, **kwargs)  file "/users/ngm/.virtualenvs/venv/lib/python3.6/site-packages/rest_framework/views.py" in dispatch   477.             response = self.handle_exception(exc)  file "/users/ngm/.virtualenvs/venv/lib/python3.6/site-packages/rest_framework/views.py" in handle_exception   437.             self.raise_uncaught_exception(exc)  file "/users/ngm/.virtualenvs/venv/lib/python3.6/site-packages/rest_framework/views.py" in raise_uncaught_exception   448.         raise exc  file "/users/ngm/.virtualenvs/venv/lib/python3.6/site-packages/rest_framework/views.py" in dispatch   474.             response = handler(request, *args, **kwargs)  file "/users/ngm/.virtualenvs/venv/lib/python3.6/site-packages/rest_framework_swagger/views.py" in   29.             schema = generator.get_schema(request=request)  file "/users/ngm/.virtualenvs/venv/lib/python3.6/site-packages/rest_framework/schemas.py" in get_schema   240.         links = self.get_links(request)  file "/users/ngm/.virtualenvs/venv/lib/python3.6/site-packages/rest_framework/schemas.py" in get_links   269.             link = self.get_link(path, method, view)  file "/users/ngm/.virtualenvs/venv/lib/python3.6/site-packages/rest_framework/schemas.py" in get_link   368.         fields += self.get_serializer_fields(path, method, view)  file "/users/ngm/.virtualenvs/venv/lib/python3.6/site-packages/rest_framework/schemas.py" in get_serializer_fields   484.         field in serializer.fields.values():  file "/users/ngm/.virtualenvs/venv/lib/python3.6/site-packages/rest_framework/serializers.py" in fields   336.             key, value in self.get_fields().items():  file "/users/ngm/.virtualenvs/venv/lib/python3.6/site-packages/rest_framework/serializers.py" in get_fields   977.                 field_name, info, model, depth  file "/users/ngm/.virtualenvs/venv/lib/python3.6/site-packages/rest_framework/serializers.py" in build_field   1112.         return self.build_unknown_field(field_name, model_class)  file "/users/ngm/.virtualenvs/venv/lib/python3.6/site-packages/rest_framework/serializers.py" in build_unknown_field   1219.             (field_name, model_class.__name__)  exception type: improperlyconfigured @ /api/v1/swagger/ exception value: field name `username` not valid model `customuser`. request information: user: m@gmail.com  get: no data  post: no post data  files: no files data  cookies: pycharm-e15616ac = '2060dfb1-f0e4-45e9-86d8-8da3a138638f' _ga = 'ga1.1.1443617960.1490863255' tabstyle = 'html-tab' csrftoken = 'evhygro5559isd1q355nh0mpile2lds6rjfbgcbdlq7tn7kfkoumvjsczinsjhnv' sessionid = '6989fmhdxu10znsview00sw7d0m2w2pg'  meta: android_sdk_home = '/users/ngm/documents/android-sdk-macosx' app_settings = 'config.developmentconfig' apple_pubsub_socket_render = '/private/tmp/com.apple.launchd.zl9fpdgy5r/render' content_length = '' content_type = 'text/plain' csrf_cookie = 'evhygro5559isd1q355nh0mpile2lds6rjfbgcbdlq7tn7kfkoumvjsczinsjhnv' database_url = 'postgresql://postgres:postgres@localhost/thanhthi' display = '/private/tmp/com.apple.launchd.swialsi3ib/org.macosforge.xquartz:0' django_settings_module = 'hou.settings' dyld_library_path = '/users/ngm/torch/install/lib:' gateway_interface = 'cgi/1.1' gem_home = '/users/ngm/.rvm/gems/ruby-2.3.1' gem_path = '/users/ngm/.rvm/gems/ruby-2.3.1:/users/ngm/.rvm/gems/ruby-2.3.1@global' home = '/users/ngm' http_accept = 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' http_accept_encoding = 'gzip, deflate, sdch, br' http_accept_language = 'en-us,en;q=0.8,vi;q=0.6,ko;q=0.4' http_cache_control = 'max-age=0' http_connection = 'keep-alive' http_cookie = 'pycharm-e15616ac=2060dfb1-f0e4-45e9-86d8-8da3a138638f; _ga=ga1.1.1443617960.1490863255; tabstyle=html-tab; csrftoken=evhygro5559isd1q355nh0mpile2lds6rjfbgcbdlq7tn7kfkoumvjsczinsjhnv; sessionid=6989fmhdxu10znsview00sw7d0m2w2pg' http_host = 'localhost:8000' http_upgrade_insecure_requests = '1' http_user_agent = 'mozilla/5.0 (macintosh; intel mac os x 10_12_1) applewebkit/537.36 (khtml, gecko) chrome/56.0.2924.87 safari/537.36' irbrc = '/users/ngm/.rvm/rubies/ruby-2.3.1/.irbrc' lc_ctype = 'utf-8' ld_library_path = '/users/ngm/torch/install/lib:' logname = 'ngm' lua_cpath = '/users/ngm/torch/install/lib/?.dylib;/users/ngm/.luarocks/lib/lua/5.1/?.so;/users/ngm/torch/install/lib/lua/5.1/?.so;./?.so;/usr/local/lib/lua/5.1/?.so;/usr/local/lib/lua/5.1/loadall.so' lua_path = '/users/ngm/.luarocks/share/lua/5.1/?.lua;/users/ngm/.luarocks/share/lua/5.1/?/init.lua;/users/ngm/torch/install/share/lua/5.1/?.lua;/users/ngm/torch/install/share/lua/5.1/?/init.lua;./?.lua;/users/ngm/torch/install/share/luajit-2.1.0-beta1/?.lua;/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua' my_ruby_home = '/users/ngm/.rvm/rubies/ruby-2.3.1' ndk_module_path = '/users/ngm/documents/ndk/android-ndk-r10e' oldpwd = '/users/ngm/pycharmprojects' path = '/users/ngm/.virtualenvs/venv/bin:/library/frameworks/python.framework/versions/3.6/bin:/library/frameworks/python.framework/versions/2.7/bin:/users/ngm/.rvm/gems/ruby-2.3.1/bin:/users/ngm/.rvm/gems/ruby-2.3.1@global/bin:/users/ngm/.rvm/rubies/ruby-2.3.1/bin:/users/ngm/downloads/apache-maven-3.3.9/bin:/users/ngm/documents/ndk/android-ndk-r10e:/users/ngm/documents/android-sdk-macosx/tools:/users/ngm/documents/android-sdk-macosx/platform-tools:/library/frameworks/python.framework/versions/3.4/bin:/users/ngm/torch/install/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/x11/bin:/users/ngm/.rvm/bin' path_info = '/api/v1/swagger/' ps1 = '(venv) \\h:\\w \\u\\$ ' pwd = '/users/ngm/pycharmprojects/hou' query_string = '' remote_addr = '127.0.0.1' remote_host = '' request_method = 'get' ruby_version = 'ruby-2.3.1' run_main = 'true' script_name = '' server_name = '1.0.0.127.in-addr.arpa' server_port = '8000' server_protocol = 'http/1.1' server_software = 'wsgiserver/0.2' shell = '/bin/bash' shlvl = '1' ssh_auth_sock = '/private/tmp/com.apple.launchd.ycnfwnh4ib/listeners' term = 'xterm-256color' term_program = 'apple_terminal' term_program_version = '387' term_session_id = '5a3a4778-0648-46f3-899e-d60cf50f5fab' tmpdir = '/var/folders/r7/dclxzr590qx2p1_lmgq9_k040000gn/t/' tz = 'utc' user = 'ngm' virtual_env = '/users/ngm/.virtualenvs/venv' xpc_flags = '0x0' xpc_service_name = '0' _ = '/users/ngm/.virtualenvs/venv/bin/python' __cf_user_text_encoding = '0x1f5:0x0:0x0' __pyvenv_launcher__ = '/users/ngm/.virtualenvs/venv/bin/python' _system_arch = 'x86_64' _system_name = 'osx' _system_type = 'darwin' _system_version = '10.12' rvm_bin_path = '/users/ngm/.rvm/bin' rvm_path = '/users/ngm/.rvm' rvm_prefix = '/users/ngm' rvm_version = '1.27.0 (latest)' wsgi.errors = <_io.textiowrapper name='<stderr>' mode='w' encoding='utf-8'> wsgi.file_wrapper = '' wsgi.input = <_io.bufferedreader name=7> wsgi.multiprocess = false wsgi.multithread = true wsgi.run_once = false wsgi.url_scheme = 'http' wsgi.version =   settings: using settings module hou.settings absolute_url_overrides = {} account_authentication_method = 'email' account_email_required = true account_unique_email = true account_username_required = false account_user_model_username_field = 'email' admins = [] allowed_hosts = ['192.168.0.104', '192.168.0.102', 'localhost', '127.0.0.1'] append_slash = true authentication_backends =  auth_password_validators = '********************' auth_user_model = 'api.customuser' base_dir = '/users/ngm/pycharmprojects/hou' caches = {'default': {'backend': 'django.core.cache.backends.locmem.locmemcache'}} cache_middleware_alias = 'default' cache_middleware_key_prefix = '********************' cache_middleware_seconds = 600 csrf_cookie_age = 31449600 csrf_cookie_domain = none csrf_cookie_httponly = false csrf_cookie_name = 'csrftoken' csrf_cookie_path = '/' csrf_cookie_secure = false csrf_failure_view = 'django.views.csrf.csrf_failure' csrf_header_name = 'http_x_csrftoken' csrf_trusted_origins = [] databases = {'default': {'engine': 'django.db.backends.postgresql', 'name': 'hou', 'user': 'postgres', 'password': '********************', 'host': '127.0.0.1', 'port': '', 'atomic_requests': false, 'autocommit': true, 'conn_max_age': 0, 'options': {}, 'time_zone': none, 'test': {'charset': none, 'collation': none, 'name': none, 'mirror': none}}} database_routers = [] data_upload_max_memory_size = 2621440 data_upload_max_number_fields = 1000 datetime_format = 'n j, y, p' datetime_input_formats = ['%y-%m-%d %h:%m:%s', '%y-%m-%d %h:%m:%s.%f', '%y-%m-%d %h:%m', '%y-%m-%d', '%m/%d/%y %h:%m:%s', '%m/%d/%y %h:%m:%s.%f', '%m/%d/%y %h:%m', '%m/%d/%y', '%m/%d/%y %h:%m:%s', '%m/%d/%y %h:%m:%s.%f', '%m/%d/%y %h:%m', '%m/%d/%y'] date_format = 'n j, y' date_input_formats = ['%y-%m-%d', '%m/%d/%y', '%m/%d/%y', '%b %d %y', '%b %d, %y', '%d %b %y', '%d %b, %y', '%b %d %y', '%b %d, %y', '%d %b %y', '%d %b, %y'] debug = true debug_propagate_exceptions = false decimal_separator = '.' default_charset = 'utf-8' default_content_type = 'text/html' default_exception_reporter_filter = 'django.views.debug.safeexceptionreporterfilter' default_file_storage = 'django.core.files.storage.filesystemstorage' default_from_email = 'webmaster@localhost' default_index_tablespace = '' default_tablespace = '' disallowed_user_agents = [] email_backend = 'django.core.mail.backends.smtp.emailbackend' email_host = 'smtp.gmail.com' email_host_password = '********************' email_host_user = 'ez.web.video.cast@gmail.com' email_port = 587 email_ssl_certfile = none email_ssl_keyfile = '********************' email_subject_prefix = '[django] ' email_timeout = none email_use_ssl = false email_use_tls = true file_charset = 'utf-8' file_upload_directory_permissions = none file_upload_handlers = ['django.core.files.uploadhandler.memoryfileuploadhandler', 'django.core.files.uploadhandler.temporaryfileuploadhandler'] file_upload_max_memory_size = 2621440 file_upload_permissions = none file_upload_temp_dir = none first_day_of_week = 0 fixture_dirs = [] force_script_name = none format_module_path = none ignorable_404_urls = [] installed_apps = ['django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'rest_framework', 'api.apps.apiconfig', 'rest_framework.authtoken', 'rest_auth', 'django.contrib.sites', 'allauth', 'allauth.account', 'rest_auth.registration', 'allauth.socialaccount', 'allauth.socialaccount.providers.facebook', 'phonenumber_field', 'rest_framework_swagger'] internal_ips = [] languages = [('af', 'afrikaans'), ('ar', 'arabic'), ('ast', 'asturian'), ('az', 'azerbaijani'), ('bg', 'bulgarian'), ('be', 'belarusian'), ('bn', 'bengali'), ('br', 'breton'), ('bs', 'bosnian'), ('ca', 'catalan'), ('cs', 'czech'), ('cy', 'welsh'), ('da', 'danish'), ('de', 'german'), ('dsb', 'lower sorbian'), ('el', 'greek'), ('en', 'english'), ('en-au', 'australian english'), ('en-gb', 'british english'), ('eo', 'esperanto'), ('es', 'spanish'), ('es-ar', 'argentinian spanish'), ('es-co', 'colombian spanish'), ('es-mx', 'mexican spanish'), ('es-ni', 'nicaraguan spanish'), ('es-ve', 'venezuelan spanish'), ('et', 'estonian'), ('eu', 'basque'), ('fa', 'persian'), ('fi', 'finnish'), ('fr', 'french'), ('fy', 'frisian'), ('ga', 'irish'), ('gd', 'scottish gaelic'), ('gl', 'galician'), ('he', 'hebrew'), ('hi', 'hindi'), ('hr', 'croatian'), ('hsb', 'upper sorbian'), ('hu', 'hungarian'), ('ia', 'interlingua'), ('id', 'indonesian'), ('io', 'ido'), ('is', 'icelandic'), ('it', 'italian'), ('ja', 'japanese'), ('ka', 'georgian'), ('kk', 'kazakh'), ('km', 'khmer'), ('kn', 'kannada'), ('ko', 'korean'), ('lb', 'luxembourgish'), ('lt', 'lithuanian'), ('lv', 'latvian'), ('mk', 'macedonian'), ('ml', 'malayalam'), ('mn', 'mongolian'), ('mr', 'marathi'), ('my', 'burmese'), ('nb', 'norwegian bokmål'), ('ne', 'nepali'), ('nl', 'dutch'), ('nn', 'norwegian nynorsk'), ('os', 'ossetic'), ('pa', 'punjabi'), ('pl', 'polish'), ('pt', 'portuguese'), ('pt-br', 'brazilian portuguese'), ('ro', 'romanian'), ('ru', 'russian'), ('sk', 'slovak'), ('sl', 'slovenian'), ('sq', 'albanian'), ('sr', 'serbian'), ('sr-latn', 'serbian latin'), ('sv', 'swedish'), ('sw', 'swahili'), ('ta', 'tamil'), ('te', 'telugu'), ('th', 'thai'), ('tr', 'turkish'), ('tt', 'tatar'), ('udm', 'udmurt'), ('uk', 'ukrainian'), ('ur', 'urdu'), ('vi', 'vietnamese'), ('zh-hans', 'simplified chinese'), ('zh-hant', 'traditional chinese')] languages_bidi = ['he', 'ar', 'fa', 'ur'] language_code = 'en-us' language_cookie_age = none language_cookie_domain = none language_cookie_name = 'django_language' language_cookie_path = '/' locale_paths = [] logging = {} logging_config = 'logging.config.dictconfig' login_redirect_url = '/accounts/profile/' login_url = '/accounts/login/' logout_redirect_url = none managers = [] media_root = '/users/ngm/pycharmprojects/hou/hou/media' media_url = '/media/' message_storage = 'django.contrib.messages.storage.fallback.fallbackstorage' 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.messages.middleware.messagemiddleware', 'django.middleware.clickjacking.xframeoptionsmiddleware'] middleware_classes = ['django.middleware.common.commonmiddleware', 'django.middleware.csrf.csrfviewmiddleware'] migration_modules = {} month_day_format = 'f j' number_grouping = 0 password_hashers = '********************' password_reset_timeout_days = '********************' phonenumber_default_region = 'vn' prepend_www = false project_dir = '/users/ngm/pycharmprojects/hou/hou' rest_framework = {'default_filter_backends': ('django_filters.rest_framework.djangofilterbackend',)} root_urlconf = 'hou.urls' secret_key = '********************' secure_browser_xss_filter = false secure_content_type_nosniff = false secure_hsts_include_subdomains = false secure_hsts_seconds = 0 secure_proxy_ssl_header = none secure_redirect_exempt = [] secure_ssl_host = none secure_ssl_redirect = false server_email = 'root@localhost' session_cache_alias = 'default' session_cookie_age = 1209600 session_cookie_domain = none session_cookie_httponly = true session_cookie_name = 'sessionid' session_cookie_path = '/' session_cookie_secure = false session_engine = 'django.contrib.sessions.backends.db' session_expire_at_browser_close = false session_file_path = none session_save_every_request = false session_serializer = 'django.contrib.sessions.serializers.jsonserializer' settings_module = 'hou.settings' short_datetime_format = 'm/d/y p' short_date_format = 'm/d/y' signing_backend = 'django.core.signing.timestampsigner' silenced_system_checks = [] site_id = 1 staticfiles_dirs = [] staticfiles_finders = ['django.contrib.staticfiles.finders.filesystemfinder', 'django.contrib.staticfiles.finders.appdirectoriesfinder'] staticfiles_storage = 'django.contrib.staticfiles.storage.staticfilesstorage' static_root = none static_url = '/static/' templates = [{'backend': 'django.template.backends.django.djangotemplates', 'dirs': [], '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']}}] test_non_serialized_apps = [] test_runner = 'django.test.runner.discoverrunner' thousand_separator = ',' time_format = 'p' time_input_formats = ['%h:%m:%s', '%h:%m:%s.%f', '%h:%m'] time_zone = 'utc' use_etags = false use_i18n = true use_l10n = true use_thousand_separator = false use_tz = true use_x_forwarded_host = false use_x_forwarded_port = false wsgi_application = 'hou.wsgi.application' x_frame_options = 'sameorigin' year_month_format = 'f y' 

here customuser model:

class customusermanager(baseusermanager):     """     custom user manager deal emails unique identifiers auth     instead of usernames. default that's used "usermanager"     """     def _create_user(self, email, password, **extra_fields):         """         creates , saves user given username, email , password.         """         if not email:             raise valueerror('users must have email address')         email = self.normalize_email(email)         user = self.model(email=email, **extra_fields)         user.set_password(password)         user.save(using=self._db)         return user      def create_user(self, email, password=none, **extra_fields):         extra_fields.setdefault('is_staff', false)         extra_fields.setdefault('is_superuser', false)         return self._create_user(email, password, **extra_fields)      def create_superuser(self, email, password, **extra_fields):         extra_fields.setdefault('is_staff', true)         extra_fields.setdefault('is_superuser', true)         extra_fields.setdefault('is_active', true)          if extra_fields.get('is_staff') not true:             raise valueerror('superuser must have is_staff=true.')         if extra_fields.get('is_superuser') not true:             raise valueerror('superuser must have is_superuser=true.')         return self._create_user(email, password, **extra_fields)   class customuser(abstractbaseuser, permissionsmixin):     email = models.emailfield(unique=true)     first_name = models.charfield(_('first name'), max_length=30, blank=true)     last_name = models.charfield(_('last name'), max_length=30, blank=true)     is_staff = models.booleanfield(         _('staff status'),         default=false,         help_text=_('designates whether user can log admin site.'),     )     is_active = models.booleanfield(         _('active'),         default=true,         help_text=_(             'designates whether user should treated active. '             'unselect instead of deleting accounts.'         ),     )     date_joined = models.datetimefield(_('date joined'), default=timezone.now)      objects = customusermanager()     username_field = 'email'      def __unicode__(self):         return self.email      def get_full_name(self):         """         returns first_name plus last_name, space in between.         """         full_name = '%s %s' % (self.first_name, self.last_name)         return full_name.strip()      def get_short_name(self):         "returns short name user."         return self.first_name      def email_user(self, subject, message, from_email=none, **kwargs):         """         sends email user.         """         send_mail(subject, message, from_email, [self.email], **kwargs) 

you should remove "username" serializer's field list.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -