英文:
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)
其中activate
是backend_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('activate/<uidb64>/<token>', backend.activate, name='activate')
]
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("", include("shop.urls")),
]
# app shop/urls.py
from django.urls import path
from shop.views import catalog
urlpatterns = [
path("", catalog.CatalogueView.as_view(), name="home"),
]
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论