Django 2.0:组合路径和re_path得到NoReverseMatch错误

时间:2018-02-20 09:53:21

标签: python django python-3.x django-2.0

在项目的path中使用urls.py,并在应用的re_path中使用urls.py,我收到NoReverseMatch错误,我的项目urls.py

from django.contrib import admin
from django.urls import path, include, re_path

urlpatterns = [
    path('user/', include('user.urls', namespace='user'))
]

我的应用urls.py

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

我无法获取正确的网址,错误消息:

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

1 个答案:

答案 0 :(得分:2)

你需要在将uuid发送到网址

之前对其进行解码

喜欢uuid.decode()