django-rest-registration 0.5.1引发RESET_PASSWORD_VERIFICATION_URL和RESET_PASSWORD_VERIFICATION_URL均未设置,即使已设置

时间:2019-09-21 16:50:19

标签: python django django-rest-framework django-views django-authentication

我正在使用Django Rest Framework创建REST api,首先,我必须为用户提供注册方式。我认为django-rest-registration是实现此目的的简便方法,但是当我按照Quickstart中的说明进行操作时,我的终端抛出了以下错误:

django.core.management.base.SystemCheckError: SystemCheckError: System check identified some issues:

ERRORS:
?: (rest_registration.E001) RESET_PASSWORD_VERIFICATION_URL is not set
?: (rest_registration.E004) VERIFICATION_FROM_EMAIL is not set

System check identified 2 issues (0 silenced).

这是我的代码:

settings.py:

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

    'rest_framework',
    'corsheaders',

    'rest_registration',

    'app',
]

REST_REGISTRATION = {
    'REGISTER_VERIFICATION_ENABLED': False,
    'REGISTER_EMAIL_VERIFICATION_ENABLED': False,
    'RESET_PASSWORD_VERIFICATION_ENABLED': False,
}

urlpatterns:

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('app.urls')),
     path('accounts/', include('rest_registration.api.urls')),
]

但是,当我尝试将REST_REGISTRATION更改为此:

REST_REGISTRATION = {
    'REGISTER_VERIFICATION_URL': 'https://frontend-host/verify-user/',
    'RESET_PASSWORD_VERIFICATION_URL': 'https://frontend-host/reset-password/',
    'REGISTER_EMAIL_VERIFICATION_URL': 'https://frontend-host/verify-email/',

        'VERIFICATION_FROM_EMAIL': 'no-reply@example.com',
    }

我提交了请求,我看到了另一个错误:

/ accounts / register /中的ConnectionRefusedError +追溯:

Environment:


Request Method: POST
Request URL: http://localhost:8000/accounts/register/

Django Version: 2.2.3
Python Version: 3.7.3
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'rest_framework',
 'corsheaders',
 'rest_registration',
 'app']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'corsheaders.middleware.CorsMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']



Traceback:

File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/core/handlers/exception.py" in inner
  34.             response = get_response(request)

File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response
  115.                 response = self.process_exception_by_middleware(e, request)

File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response
  113.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/views/decorators/csrf.py" in wrapped_view
  54.         return view_func(*args, **kwargs)

File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/views/generic/base.py" in view
  71.             return self.dispatch(request, *args, **kwargs)

File "/home/fullnamedebian/.local/lib/python3.7/site-packages/rest_framework/views.py" in dispatch
  495.             response = self.handle_exception(exc)

File "/home/fullnamedebian/.local/lib/python3.7/site-packages/rest_framework/views.py" in handle_exception
  455.             self.raise_uncaught_exception(exc)

File "/home/fullnamedebian/.local/lib/python3.7/site-packages/rest_framework/views.py" in dispatch
  492.             response = handler(request, *args, **kwargs)

File "/home/fullnamedebian/.local/lib/python3.7/site-packages/rest_framework/decorators.py" in handler
  55.             return func(*args, **kwargs)

File "/home/fullnamedebian/.local/lib/python3.7/site-packages/rest_registration/api/views/register.py" in register
  96.         send_verification_notification(user, signer, template_config)

File "/home/fullnamedebian/.local/lib/python3.7/site-packages/rest_registration/notifications/email.py" in send_verification_notification
  24.     send_notification(notification)

File "/home/fullnamedebian/.local/lib/python3.7/site-packages/rest_registration/notifications/email.py" in send_notification
  209.     notification.send()

File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/core/mail/message.py" in send
  291.         return self.get_connection(fail_silently).send_messages([self])

File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/core/mail/backends/smtp.py" in send_messages
  103.             new_conn_created = self.open()

File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/core/mail/backends/smtp.py" in open
  63.             self.connection = self.connection_class(self.host, self.port, **connection_params)

File "/usr/lib/python3.7/smtplib.py" in __init__
  251.             (code, msg) = self.connect(host, port)

File "/usr/lib/python3.7/smtplib.py" in connect
  336.         self.sock = self._get_socket(host, port, self.timeout)

File "/usr/lib/python3.7/smtplib.py" in _get_socket
  307.                                         self.source_address)

File "/usr/lib/python3.7/socket.py" in create_connection
  727.         raise err

File "/usr/lib/python3.7/socket.py" in create_connection
  716.             sock.connect(sa)

Exception Type: ConnectionRefusedError at /accounts/register/
Exception Value: [Errno 111] Connection refused

我添加了电子邮件设置:

# Email settings
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'localhost'
EMAIL_PORT = 8000

现在,当我提交帖子时,我只会在终端[22/Sep/2019 14:44:54] "POST /accounts/register/ HTTP/1.1" 400 13646中看到它(如果有关系,它会以红色字体绘制)。网页正在无限加载。

0 个答案:

没有答案