I'm trying to add an Email confirmation feature to my Django project, where a user has to confirm it's email using the link provided by the site.
I already added the view, the url and a template, but i keep getting the error:
Reverse for 'activate' not found. 'activate' is not a valid view function or pattern name.
1 {% autoescape off %}
2 Hi {{ user.username }},
3 Please click on the link to confirm your registration,
4 http://{{ domain }}**{% url 'activate' uidb64=uid token=token %}**
5 {% endautoescape %}
I don't know where this error is coming from, i think i defined my view properly and added it to my urls.py, i'm following this tutorial.
Here is my view:
def activate(request, uidb64, token):
try:
uid = force_text(urlsafe_base64_decode(uidb64))
user = User.objects.get(pk=uid)
except(TypeError, ValueError, OverflowError, User.DoesNotExist):
user = None
if user is not None and account_activation_token.check_token(user, token):
user.is_active = True
user.save()
login(request, user)
# return redirect('home')
return HttpResponse('Thank you for your email confirmation. Now you can login your account.')
else:
return HttpResponse('Activation link is invalid!')
The url:
from .views import activate
path("activate/<slug:(?P<uidb64>[0-9A-Za-z_\-]+)>/<slug:(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$>",
views.activate, name='activate'),
And acc_active_email.html
{% autoescape off %}
Hi {{ user.username }},
Please click on the link to confirm your registration,
http://{{ domain }}{% url 'activate' uidb64=uid token=token %}
{% endautoescape %}
Any advice is appreciated.