首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NoReverseMatch:反向查找“account_confirm_email”。[dj-rest-auth]

NoReverseMatch:反向查找“account_confirm_email”。[dj-rest-auth]
EN

Stack Overflow用户
提问于 2022-10-14 13:11:25
回答 2查看 70关注 0票数 0

我对Django很陌生。我正在尝试实现jet身份验证和社会认证。

我正在学习本教程https://jkaylight.medium.com/django-rest-framework-authentication-with-dj-rest-auth-4d5e606cde4d

我试图实现同样的,但它不起作用。

我得到了一个错误:

django.urls.exceptions.NoReverseMatch:反向表示“account_confirm_email”未找到。'account_confirm_email‘不是一个有效的视图函数或模式名

我的项目级别urls.py

代码语言:javascript
复制
from drf_spectacular.views import (
    SpectacularAPIView,
    SpectacularSwaggerView
)
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    # path('account/', include('allauth.urls')),
    path('admin/', admin.site.urls),
    path('api/user/', include('user.urls')),
    path('api/schema/', SpectacularAPIView.as_view(), name='api-schema'),
    path(
        'api/docs/',
        SpectacularSwaggerView.as_view(url_name='api-schema'),
        name='api-docs'
    ),
]

我的应用程序级urls.py

代码语言:javascript
复制
from django.urls import path, re_path
from dj_rest_auth.registration.views import RegisterView, VerifyEmailView, ConfirmEmailView
from dj_rest_auth.views import LoginView, LogoutView


from user import views

app_name = 'user'

urlpatterns = [
    path('account-confirm-email/<str:key>/', ConfirmEmailView.as_view()),
    path('register/', RegisterView.as_view()),
    path('login/', LoginView.as_view()),
    path('logout/', LogoutView.as_view()),

    path('verify-email/',
         VerifyEmailView.as_view(), name='rest_verify_email'),
    path('account-confirm-email/',
         VerifyEmailView.as_view(), name='account_email_verification_sent'),
    re_path(r'^account-confirm-email/(?P<key>[-:\w]+)/$',
            VerifyEmailView.as_view(), name='account_confirm_email'),
    path('listusers/', views.ListUsers.as_view(), name='list-users'),
]

当我试图注册一个用户时。它会导致这个错误。

我使用dj包来实现身份验证。

如果我替换电子邮件验证相关的urls从应用程序级别到项目级别。那么一切都很好。

是什么导致了这个错误?

EN

回答 2

Stack Overflow用户

发布于 2022-10-14 13:38:47

对于注册部分,您必须使用allauth,它与dj-rest-auth进行了一些集成。

此外,您还必须在settings.py中添加一些内容

代码语言:javascript
复制
INSTALLED_APPS = [
    "dj_rest_auth.registration",
    "allauth",
    "allauth.account"
]
AUTHENTICATION_BACKENDS = [
    "allauth.account.auth_backends.AuthenticationBackend",
    "django.contrib.auth.backends.ModelBackend",
]

将这些URL添加到urls.py

代码语言:javascript
复制
urlpatterns = [
    path("signup/", include("dj_rest_auth.registration.urls"))
    path("verify-email/", VerifyEmailView.as_view(), name="rest_verify_email"),
    path(
        "account-confirm-email/",
        VerifyEmailView.as_view(),
        name="account_confirm_email_sent",
    ),
    path(
        "account-confirm-email/<key>/",
        VerifyEmailView.as_view(),
        name="account_confirm_email",
    ),
]
票数 0
EN

Stack Overflow用户

发布于 2022-10-14 17:12:23

请求没有得到<str:key>。请查查你们供应的地方。它可以是从视图或模板。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74069766

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档