Django:为什么控制台电子邮件后端不发送电子邮件?

我'm trying to make an app to reset user password via email. I' m使用Django by Example第3章,并从本网站获取指导:https://simpleisbetterthancomplex.com/tutorial/2016/09/19/how-to-create-password-reset-view.html

Settings.py包含以下行:

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

连同所需的电子邮件设置 .

我进入 password_reset 视图,输入虚拟邮件,单击发送,最后将我带到 password_reset_done 视图 . 以下是控制台输出:

C:\PythonProjects\by-example-bookmarks>python manage.py runserver
Performing system checks...

System check identified no issues (0 silenced).
May 01, 2018 - 21:13:39
Django version 2.0.4, using settings 'bookmarks.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
[01/May/2018 21:13:51] "GET /account/login/ HTTP/1.1" 200 1090
[01/May/2018 21:13:57] "GET /account/password_reset/ HTTP/1.1" 200 830
[01/May/2018 21:14:04] "POST /account/password_reset/ HTTP/1.1" 302 0
[01/May/2018 21:14:05] "GET /account/password_reset/done/ HTTP/1.1" 200 602

"POST" 输出之后,我希望看到电子邮件转储以响应 .console.EmailBackend 设置,但是什么都没有 .

什么可能是模拟发送电子邮件失败的原因?

环境:

Windows 7,django 2.0,在CMD控制台上,在pipenv shell下

Edit 1 另一台机器上的问题相同 .

Edit 2 更改为 .smtp 不会更改任何内容,也不会发生错误 .

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'

Edit 3 我尝试了其他人的工作,就像这样:https://github.com/ruddra/django-reset-password/tree/master

仍然没有运气 .

Edit 4 还有一个"other people's work" . 仍然没有运气 . https://github.com/wsvincent/django-auth-tutorial

它有用吗?

Edit 5: views.py

from django.http import HttpResponse
from django.shortcuts import render
from django.contrib.auth import authenticate, login
from .forms import LoginForm
from django.contrib.auth.decorators import login_required

def user_login(request):
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            user = authenticate( username=cd['username'],
                                 password=cd['password'])
            if user is not None:
                if user.is_active:
                    login(request, user)
                    return HttpResponse('Authenticated '\
                                        'successfully')
                else:
                    return HttpResponse('Disabled account')
            else:
                return HttpResponse('Invalid login')
    else:
        form = LoginForm()
    return render(request, 'account/login.html', {'form': form})

@login_required
def dashboard(request):
    return render(request,
                  'account/dashboard.html',
                  {'section': 'dashboard'})

urls.py

from django.conf.urls import url, include
from . import views
import django.contrib.auth.views
# i think the following does not serve any purpose anymore
from django.contrib.auth import views as auth_views

urlpatterns = [
    # previous login view
    # url(r'^login/$', views.user_login, name='login'),

    # login / logout urls
    url(r'^login/$',
        django.contrib.auth.views.login,
        name='login'),
    url(r'^logout/$',
        django.contrib.auth.views.logout,
        name='logout'),
    url(r'^logout-then-login/$',
        django.contrib.auth.views.logout_then_login,
        name='logout_then_login'),
    url(r'^$', views.dashboard, name='dashboard'),
    url(r'^password-change/$',
        django.contrib.auth.views.password_change,
        name='password_change'),
    url(r'^password-change/done/$',
        django.contrib.auth.views.password_change_done,
        name='password_change_done'),

    # restore password urls
    url('^', include('django.contrib.auth.urls')),
]

edit 6 我的github回购在这里,万一有人好奇:https://github.com/jeffplata/by-example-account

回答(1)

3 years ago

它现在有效 . 正如@Burhan Khalid所建议的,非常确定有一个用户有一个有效的电子邮件 . 具体来说,我在重置视图中键入的电子邮件位于用户模型/表中 .