python - Django 2.0 : combine path and re_path got NoReverseMatch error

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

<分区>

在项目的 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})/']

最佳答案

好吧,你需要在将它发送到 url 之前解码 uuid

喜欢uuid.decode()

关于python - Django 2.0 : combine path and re_path got NoReverseMatch error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48882313/

相关文章:

python - 有没有可能在Python中获取 "importing module"中的 "imported module"?

python - 即使安装了 BeautifulSoap 的 ImportError

python - 如何在 django 命令中实现应用程序命名空间?

python - 提取括号中的单词并将提取的单词存储到集合中

python - 如果条件为 true,Scrapy 获取 href 值

python - 需要有关使用 Django/DRF 时如何处理和/或避免循环导入的架构建议

django - [django] 错误 : contenttypes couldn't be reset

python - 在 Python 中使用条件 'with' 语句

python - 导入时模拟模块全局变量

python - 将 Python 3.4.3 连接到 MySQL