Gabo Lato Gabo Lato - 6 months ago 44
Python Question

Which is the django url regex for a token as a parameter?

I want to activate my users in my django server when they follow a link from their email with a token, like this:

http://127.0.0.1:8000/user-activation/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImdhYm8iLCJ1c2VyX2lkIjoxOSwiZW1haWwiOiJsYXRvcnJlZ2FiQGdtYWlsLmNvbSIsImV4cCI6MTQ2NDE3ODk1N30.5FDKdxKxWuOkqe3rMNE-eHwmtrlWpD7EZ-EXw0yQM3U/


I have this pattern

url(r'^user-activation/(?P<id>\w+)/', views.UserActivation.as_view()),


But it's returning 404. I searched a lot and nothing seems to work. What am I doing wrong?

I couldn't find any answer that works reading

https://docs.djangoproject.com/es/1.9/ref/urls/

nor

https://docs.djangoproject.com/es/1.9/topics/http/urls/

Edit:

I've read the post

Learning Regular Expressions

But there was no example about receiving hyphens and dots at the same time, which was what caused my confusion.

The marked answer solved my problem. Thanks

Answer

Your token also includes . and - characters so you need your regex to match them also - it currently will only match word characters

url(r'^user-activation/(?P<id>[\w\.-]+)/', views.UserActivation.as_view()),
Comments