I am trying to send an activation email to users when signing up, but I keep getting a NoReverseMatch error when trying to render the URL in the template.
The error I get is:
Reverse for 'user_activation' with keyword arguments '{'uidb64': 'MiC', 'token': 'aeue9g-3a31bdff969c41c0bb1d3775a1fa98ac'}' not found. 1 pattern(s) tried: ['account/activate/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$']
urls.py
from .views import * from django.urls import re_path urlpatterns = [ re_path(r'^activate/(?P<uidb64>[0-9A-Za-z_-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', user_activation_view, name='user_activation'), # user activation view ]
template.txt
{% autoescape off %} To activate your account ({{ user.email }}), please click the link below: {{ protocol }}://{{ domain }}{% url 'user_activation' uidb64=uid token=token %} If clicking the link above doesn't work, you can copy and paste the URL in a new browser window instead. If you did not make this request, please ignore this email. {% endautoescape %}
Advertisement
Answer
The pattern for the token variable is:
<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20}
THis thus means that there are two sequence of [0-9A-Za-z]
characters: one with one to thirteen characters, and one with one to twenty characters, and these are separated by a hyphen.
Your token however has:
'aeue9g-3a31bdff969c41c0bb1d3775a1fa98ac' __ __/ _____________ ________________/ v v 6 chars 32 chars
So this does not match the specifications. If you want to accept this token, you can alter the pattern, for example to:
<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,32}