error regexp django urls

0

Why Django does not recognize my url?

my urls.py

from django.urls import path
from home.views import homePageView, activateUser

urlpatterns = [
    path('',homePageView.as_view(),name='home'),
    path('activate/([a-zA-Z0-9]{15})/$', activateUser.activate, name='activate')
]

The URL to which I agree:

http://127.0.0.1:8000/activate/9Eri2DOMYpwI5p8/

the error that shows:

  

Using the URLconf defined in cryptoassistant.urls, Django tried these   URL patterns, in this order:

     

admin / [name = 'home'] activate / ([a-zA-Z0-9] {15}) / $ [name = 'activate']   activate / ([a-zA-Z0-9] {15}) / $ [name = 'activate'] The current path,   activate / 9Eri2DOMYpwI5p8 /, did not match any of these.

    
asked by XBoss 26.06.2018 в 19:27
source

2 answers

2

I solved the problem using re_path :

from django.urls import re_path
re_path('activate/([a-zA-Z0-9]{15})/$', activateUser.activate, name='activate')
    
answered by 26.06.2018 / 20:09
source
1

You do not need to use Regex with the Path feature replaces:

path('activate/([a-zA-Z0-9]{15})/$', activateUser.activate, name='activate')

by:

path('activate/<slug:slug>)/$', activateUser.activate, name='activate')
    
answered by 26.06.2018 в 19:50