2

I am attempting to make a validation link e-mail as part of my user sign-up in Django. I have a {% url %} tag in my template however it is giving me a NoReverseMatch error with regards to the uid & token variables.

Here is the code in the template:

https://{{ domain }}{% url 'users:activate' uidb64=uid token=token%}

Here is my URL pattern:

re_path(r'^activate/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', views.activate, name='activate'),

And last of all here is my error:

django.urls.exceptions.NoReverseMatch: Reverse for 'activate' with keyword arguments '{'uidb64': b'MzY', 'token': '4xq-eb603ee3a9676d7b3edc'}' not found. 1 pattern(s) tried: ['users\\/activate/(?P<uidb64>[0-9A-Za-z_\\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$']

I have a hunch it may be something to do with the regular expression but that is not a strong point I have (yet)!

It appears to find the activation URL pattern but I cant seem to make it recognize the arguments for the url!

Zexelon
  • 495
  • 5
  • 18

1 Answers1

2

Looks like uid type is bytes instead of string. Try to decode it before pass it to template context:

# you view code
uid = uid.decode()
context['uid'] = uid
return render(requet, 'template.html', context)
neverwalkaloner
  • 46,181
  • 7
  • 92
  • 100
  • While this did not exactly provide the answer I was needed it helped me to ask the right question and is correct (I just needed some slightly different code). Turns out my issue is one with Django 2.0. This is the complete answer I was able to find https://stackoverflow.com/questions/47177696/noreversematch-with-keyword-argument-uidb64-with-django-2-0 – Zexelon Jul 10 '18 at 13:33