У меня эта ошибка, я использую Ubuntu Linux os, здесь я сделал переменную env в домашнем разделе с именем ".bash_profile", в котором я сохранил свой Gmail и прошел. Теперь проблема в том, что когда я вызываю их в файле settings.py, они не работают, но вместо этого, если я пытаюсь отправить электронное письмо и пройти туда, он работает нормально, и я получаю электронное письмо для сброса. Вещи, которые я уже пробовал:
- Элемент списка
- Одно и то же имя у обеих переменных из переменной env и в settings.py
- I ' m не использует двухфакторную аутентификацию, поэтому я разрешил менее безопасное приложение.
- Пытался использовать двухфакторную аутентификацию и следовал другому процессу.
- Почтовый идентификатор у пользователя Django, и этот пользователь тот же.
- Уже искал разные ответы о переполнении стека и других сайтах.
код выглядит следующим образом
settings.py
"""
Django settings for blog_page project.
Generated by 'django-admin startproject' using Django 2.2.6.
For more information on this file, see
https://docs.djangoproject.com/en/2.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.2/ref/settings/
"""
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '3*v_t0-f_+g1un_7k-mpt7q2=*3q+#&6!c5b1+b#$#buxwa_4e'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'blog',
'users',
'crispy_forms',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
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',
]
ROOT_URLCONF = 'blog_page.urls'
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',
],
},
},
]
WSGI_APPLICATION = 'blog_page.wsgi.application'
# Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/2.2/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/
STATIC_URL = '/static/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
CRISPY_TEMPLATE_PACK = 'bootstrap4'
LOGIN_REDIRECT_URL = 'blog-home'
LOGIN_URL = 'login'
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_USE_SSL = False
EMAIL_HOST_USER = os.environ.get('DB_USER')
EMAIL_HOST_PASSWORD = os.environ.get('DB_PASS')
DEFAULT_FROM_EMAIL = 'lkbhitesh07@gmail.com'
URL. py проекта
from django.contrib import admin
from django.urls import path, include
from users import views as user_view
from django.conf import settings
from django.conf.urls.static import static
from django.contrib.auth import views as auth_view
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('blog.urls')),
path('register/', user_view.register, name='register'),
path('login/', auth_view.LoginView.as_view(template_name='users/login.html'), name='login'),
path('logout/', auth_view.LogoutView.as_view(template_name='users/logout.html'), name='logout'),
path('profile/', user_view.profile, name='profile'),
path('password-reset/', auth_view.PasswordResetView.as_view(template_name='users/password_reset.html'), name='password_reset'),
path('password-reset/done/', auth_view.PasswordResetDoneView.as_view(template_name='users/password_reset_done.html'), name='password_reset_done'),
path('password-reset-confirm/<uidb64>/<token>/', auth_view.PasswordResetConfirmView.as_view(template_name='users/password_reset_confirm.html'), name='password_reset_confirm'),
path('password-reset-complete/', auth_view.PasswordResetCompleteView.as_view(template_name='users/password_reset_complete.html'), name='password_reset_complete'),
]
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
ОШИБКА отображается в терминале
atching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
May 07, 2020 - 10:16:44
Django version 2.2.6, using settings 'blog_page.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[07/May/2020 10:16:49] "GET /password-reset/ HTTP/1.1" 200 4013
[07/May/2020 10:16:51] "GET /password-reset/ HTTP/1.1" 200 4013
[07/May/2020 10:16:51] "GET /static/blog/main.css HTTP/1.1" 304 0
[07/May/2020 10:16:52] "GET /password-reset/ HTTP/1.1" 200 4013
[07/May/2020 10:16:52] "GET /static/blog/main.css HTTP/1.1" 304 0
Internal Server Error: /password-reset/
Traceback (most recent call last):
File "/home/hitesh/.local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/home/hitesh/.local/lib/python3.6/site-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/hitesh/.local/lib/python3.6/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/hitesh/.local/lib/python3.6/site-packages/django/views/generic/base.py", line 71, in view
return self.dispatch(request, *args, **kwargs)
File "/home/hitesh/.local/lib/python3.6/site-packages/django/utils/decorators.py", line 45, in _wrapper
return bound_method(*args, **kwargs)
File "/home/hitesh/.local/lib/python3.6/site-packages/django/utils/decorators.py", line 142, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/home/hitesh/.local/lib/python3.6/site-packages/django/contrib/auth/views.py", line 220, in dispatch
return super().dispatch(*args, **kwargs)
File "/home/hitesh/.local/lib/python3.6/site-packages/django/views/generic/base.py", line 97, in dispatch
return handler(request, *args, **kwargs)
File "/home/hitesh/.local/lib/python3.6/site-packages/django/views/generic/edit.py", line 142, in post
return self.form_valid(form)
File "/home/hitesh/.local/lib/python3.6/site-packages/django/contrib/auth/views.py", line 233, in form_valid
form.save(**opts)
File "/home/hitesh/.local/lib/python3.6/site-packages/django/contrib/auth/forms.py", line 295, in save
email, html_email_template_name=html_email_template_name,
File "/home/hitesh/.local/lib/python3.6/site-packages/django/contrib/auth/forms.py", line 250, in send_mail
email_message.send()
File "/home/hitesh/.local/lib/python3.6/site-packages/django/core/mail/message.py", line 291, in send
return self.get_connection(fail_silently).send_messages([self])
File "/home/hitesh/.local/lib/python3.6/site-packages/django/core/mail/backends/smtp.py", line 110, in send_messages
sent = self._send(message)
File "/home/hitesh/.local/lib/python3.6/site-packages/django/core/mail/backends/smtp.py", line 126, in _send
self.connection.sendmail(from_email, recipients, message.as_bytes(linesep='\r\n'))
File "/usr/lib/python3.6/smtplib.py", line 867, in sendmail
raise SMTPSenderRefused(code, resp, from_addr)
smtplib.SMTPSenderRefused: (530, b'5.7.0 Authentication Required. Learn more at\n5.7.0 https://support.google.com/mail/?p=WantAuthError t21sm3542961pgu.39 - gsmtp', 'lkbhitesh07@gmail.com')
[07/May/2020 10:17:02] "POST /password-reset/ HTTP/1.1" 500 132443
изображение ошибки
пожалуйста, дайте мне знать, если мне нужно показать какие-либо другой код.