@DACV

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

Djangoのパスワードリセットのリンクを取得したい

解決したいこと

Djangoのパスワードリセットのリンクを取得したい。

発生している問題・エラー

[03/Apr/2021 00:23:00] "GET /accounts/password_reset/ HTTP/1.1" 200 1903
[03/Apr/2021 00:23:11] "POST /accounts/password_reset/ HTTP/1.1" 302 0
[03/Apr/2021 00:23:11] "GET /accounts/password_reset/password_reset/done/ HTTP/1.1" 20
0 1543

accounts/password_reset/で任意のメールアドレスを入れてボタンを押してもメールが届かない。

期待する結果

Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Subject: Password reset on 127.0.0.1:8000
From: webmaster@localhost
To: 自分の@gmail.com
Date: -------
Message-ID: <----------->

You're receiving this email because you required a password reset for
your user account at 127.0.0.1:8000.

Please go to the following page and choose a new password:

-------------------

Your username, in case you've forgotten: -----

自分で試したこと

『Djangoのツボとコツがゼッタイにわかる本』に載って通りにやったつもりです。(上の結果も本に載っている通りです)
/emailでメールを送ることはできるのでメールアカウントの設定の問題ではないと思います。

本にはこれだけしか指示がありませんでした。

#setting.py
.
.
.
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
DEFULT_FROM_EMAIL = '自分の@gmail.com'
EMAIL_HOST = 'smtp.sendgrid.net'
EMAIL_HOST_USER = 'apikey'
EMAIL_HOST_PASSWORD = '発行したAPキー'
EMAIL_PORT = 587
EMAIL_USE_TLS = True


#urls.py
from django.contrib import admin
from django.urls import path, include
from .views import emailfunc
from django.contrib.auth import views as auth_views

urlpatterns = [
    path('admin/', admin.site.urls),
    path('accounts/', include('django.contrib.auth.urls')),
    path('email/', emailfunc),
    path(
        'change-password/',
        auth_views.PasswordChangeView.as_view(template_name='change-password.html'),
    ),
    ]

#views.py
from django.core.mail import send_mail
from django.http import HttpResponse

def emailfunc(request):
    send_mail(
        'タイトル',
        '本文.',
        '送信元アドレス',
        ['送信先アドレス'],
        fail_silently=False,
    )
    return HttpResponse('')

1 likes

No Answers yet.

Your answer might help someone💌