0

In Django 2.0, I deal with uid and token for user email confirmation.

'uid': urlsafe_base64_encode(force_bytes(user.pk)), 'token': PasswordResetTokenGenerator().make_token(user),

My urlpatterns is like below, however pattern is not found:

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

The error message is like this:

Reverse for 'confirm-user-email' with keyword arguments '{'uidb64': b'Mw', 'token': '4t9-a61218655569c14203b8'}' not found. 1 pattern(s) tried: ['member\/confirm/(?P[0-9A-Za-z_\-]+)/(?P[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$']

Alasdair
  • 298,606
  • 55
  • 578
  • 516
namwoo
  • 89
  • 5
  • The regex looks ok to me. The reverse is failing because `uidb64` is bytes `b'Mw'`. – Alasdair Jan 29 '18 at 10:00
  • @Alasdair Thanks:) I've just solved it. And I will figure it out why it needs decode() in django 2.0. – namwoo Jan 29 '18 at 10:06
  • My answer links to [the release notes](https://docs.djangoproject.com/en/2.0/releases/2.0/#removed-support-for-bytestrings-in-some-places) which explain why you need to `decode()` in Django 2.0. – Alasdair Jan 29 '18 at 10:07

0 Answers0