I have read similar questions but I cannot understand why this is not working. I am trying to send a reactivation email to user when they click on a link. The activation link is generated properly when the user signs up and the email is sent, but when I try to call the same function again to reactivate link, it is not working saying it is missing one parameter. Here's the function:
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'),
Is this the right way to pass on the request and user parameters to the function?
EDIT: This is the link that is used to redirect user:
<p><a href="{% url 'reactivate' %}">Click here</a> to resend the activation email.</p>
change your urlpattern to this
urlpatterns = [
url(r'^reactivate/$', views.sendactivationmail, name='reactivate'),
.....
]
and html to, but the user has to be logged in to use this link. remember that
<p><a href="{% url 'reactivate' request.user %}">Click here</a> to resend the activation email.</p>