djangoregexurl-pattern

How to fix Django regular expression problem


Django Rest Framework after User registration sends out an email for the new User to verify the email address. The link attached is like:

https://my_domain.com/api/verify_email/?token=ddfddjrf....fddkfjdjh

My api.urls.py file looks like:

api.urls.py
from django.urls import re_path
from . import views

urlpatterns = [
   re_path(r'^verify_email/(?P<token>[\w.-]+)/',views.verify_email, name="verify_email"),
[

And in project urls.py

...
path('api/', include("api.urls")),
...

When I try to run that link I get:

Page not found (404) The current path api/verify_email/, didn't match any of these.

I can see a URL pattern from the URL.conf: Django tried these URL patterns,in this order.

...    
api/ ^verify_email/(?P<token>[\w.-]+)/ [name='verify_email']    
...

I hope somebody can help because I can't find a solution somewhere .... And I tried several things to fix it. But without any success. Thank's a lot.

Greetings RR


Solution

  • As the error says, it is lacking the token, so you visit it with:

    /api/verify_email/ddfddjrf....fddkfjdjh/

    not as part of the querystring.