尝试在Django中发送验证电子邮件时,出现错误。

huangapple go评论63阅读模式
英文:

Trying to send Validation Email in django, getting error

问题

我正在尝试在Django中创建用户时发送验证电子邮件。以前它是这样工作的,但后来我对URL进行了一些重构,并使用了urlpattern = UrlPattern()urlpattern.register(UserView)。这是在主Django项目的url.py中。

在应用程序的url.py中,我有以下内容:

from django.urls import path
from myapp import backend

urlpatterns = [
    path('activate/<uidb64>/<token>', backend.activate, name='activate')
]

这是项目的URL:

from myapp.views import RoomView, UserView
from django_request_mapping import UrlPattern

urlpatterns = UrlPattern()

urlpatterns.register(UserView)
urlpatterns.register(RoomView)

其中activatebackend_logic中的一个函数,以前它可以工作并向请求中的电子邮件发送电子邮件。然而,现在我得到了错误信息:

找不到名称为'activate'的反向视图。'activate'不是有效的视图函数或模式名称。

英文:

Im trying to send validation email when creating a user in django. It used to work like that but then I did some refactoring on the URLs and used urlpattern = UrlPattern() and urlpattern.register(UserView). That is in the main django project url.py

In the app url.py Im having

from django.urls import path
from myapp import backend


urlpatterns = [
    path(&#39;activate/&lt;uidb64&gt;/&lt;token&gt;&#39;, backend.activate, name=&#39;activate&#39;)

    ]

Here are the project urls

from myapp.views import RoomView, UserView
from django_request_mapping import UrlPattern

urlpatterns = UrlPattern()

urlpatterns.register(UserView)
urlpatterns.register(RoomView)

where activate is a function in backend_logic, which used to work and send the email to the one from request. However, now Im getting the error

> Reverse for 'activate' not found. 'activate' is not a valid view function or pattern name.

答案1

得分: 1

运行 python manage.py show_urls 查看您的URL是否正确注册。(它是django-extensions包的一部分,非常有用。)

如果没有正确注册,请将您的应用程序的URL包含在项目的urls.py中。

示例:

# 项目的urls.py
from django.urls import path, include

urlpatterns = [
    path("", include("shop.urls")),
]
# 应用程序shop/urls.py
from django.urls import path

from shop.views import catalog

urlpatterns = [
    path("", catalog.CatalogueView.as_view(), name="home"),
]
英文:

Run python manage.py show_urls to see is your URL registered properly or not. (It's part of django-extensions package, very useful.)

If not, include yours app's urls into your project urls.py.

Example:

# project urls.py
from django.urls import path, include

urlpatterns = [
    path(&quot;&quot;, include(&quot;shop.urls&quot;)),
]
# app shop/urls.py
from django.urls import path

from shop.views import catalog

urlpatterns = [
    path(&quot;&quot;, catalog.CatalogueView.as_view(), name=&quot;home&quot;),
]

huangapple
  • 本文由 发表于 2023年8月9日 05:13:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/76863232.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定