Django 2.0:组合路径和 re_path 出现 NoReverseMatch 错误

Django 2.0: combine path and re_path got NoReverseMatch error

在项目的 urls.py 中使用 path,并在应用的 urls.py 中使用 re_path,我得到了 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'),
]

我无法得到正确的url,错误信息:

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})/']

好吧,您需要先解码 uuid,然后再将其发送到 url

喜欢uuid.decode()