gpt4 book ai didi

python - Django 重新发送激活链接,缺少 1 个必需的位置参数 : 'user'

转载 作者:行者123 更新时间:2023-12-01 07:41:34 25 4
gpt4 key购买 nike

我读过类似的问题,但我不明白为什么这不起作用。当用户单击链接时,我试图向他们发送重新激活电子邮件。当用户注册并发送电子邮件时,激活链接会正确生成,但是当我尝试再次调用同一函数来重新激活链接时,它不起作用,说它缺少一个参数。函数如下:

acounts/views.py

def sendactivationmail(request, user):
# Creating token and masing uid of user
token = default_token_generator.make_token(user)
uid = urlsafe_base64_encode(force_bytes(user.pk)).decode()
# Sending email for email verification
subject = 'Please Verify Your Email'
from_email = settings.DEFAULT_FROM_EMAIL
to_email = [user.email]
context = {
'url': settings.BASE_URL + reverse('user-activation-link', kwargs={
'uidb64': uid,
'token': token,
}),
}
contact_message = render_to_string('verify_email.html', context)
plain_message = strip_tags(contact_message)
send_mail(subject, plain_message, from_email, to_email, html_message=contact_message, fail_silently=True)

return redirect(reverse('login'))

accounts/urls.py

from django.conf.urls import url
from .views import *
from . import views
from urllib import request
from django.contrib.auth.models import User


urlpatterns = [
url(r'^reactivate/$', views.sendactivationmail(request, User), name='reactivate'),

这是将请求用户参数传递给函数的正确方法吗?

编辑:这是用于重定向用户的链接:

<p><a href="{% url 'reactivate' %}">Click here</a> to resend the activation email.</p>

最佳答案

将你的 urlpattern 更改为此

urlpatterns = [
url(r'^reactivate/$', views.sendactivationmail, name='reactivate'),
.....
]

和 html,但用户必须登录才能使用此链接。记住这一点

<p><a href="{% url 'reactivate' request.user %}">Click here</a> to resend the activation email.</p>

关于python - Django 重新发送激活链接,缺少 1 个必需的位置参数 : 'user' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56680485/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com