【问题标题】:Python Django NoReverseMatch TemplatePython Django NoReverseMatch 模板
【发布时间】:2020-06-03 13:51:52
【问题描述】:

我配置了路径并制作了模板,但是当我尝试运行服务器时它给出了

NoReverseMatch 在 /password-reset/ 未找到“password_reset_confirm”的反向。 'password_reset_confirm' 不是有效的视图函数或模式名称。 请求方法:POST 请求网址:http://localhost:8000/password-reset/ Django 版本:3.0.6 异常类型:NoReverseMatch 异常值:
未找到“password_reset_confirm”的反向。 'password_reset_confirm' 不是有效的视图函数或模式名称。 错误。 我的 urls.py

from django.contrib import admin
from django.contrib.auth import views as auth_views
from django.urls import path, include
from users import views as user_views
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [



    path('admin/', admin.site.urls),
    path('register/', user_views.register, name= 'register'),
    path('profile/', user_views.profile, name='profile'),
    path('login/', auth_views.LoginView.as_view(template_name = 'users/login.html'), name='login'),
    path('logout/', auth_views.LogoutView.as_view(template_name = 'users/logout.html'), name='logout'),
    path('password-reset/', auth_views.PasswordResetView.as_view(template_name='users/password_reset.html'),
         name='password_reset'),
    path('password-reset/done/',

auth_views.PasswordResetDoneView.as_view(template_name='users/password_reset_done.html'), name='password_reset_done'), path('密码-重置-确认///', auth_views.PasswordResetConfirmView.as_view(template_name='users/password_reset_confirm.html'), name='password_reset_confirm '),

    path('', include('blog.urls'))
]
if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)


and my template 
{% extends "blog/base.html" %}
{% load crispy_forms_tags %}
{% block content %}
    <div class = "content section">
        <form method="POST">
            {% csrf_token %}
            <fieldset class= "form-group">
                <legend class = "border-bottom mb-4">Reset Password</legend>
                {{form|crispy}}
            </fieldset>
            <div class = "form-group">
                <button class="btn btn-outline-info" type ="submit"> Reset Password </button>
            </div>
        </form>

    </div>


{% endblock content %}

您能告诉我我的项目有什么问题吗?谢谢

【问题讨论】:

    标签: python django url django-templates


    【解决方案1】:

    您的'password_reset_confirm ' 名称中似乎有一个空格

    'password_reset_confirm '
                           ^
    

    不确定 django 处理得如何。如果这不是问题,请在模板中反向调用 URL 的位置发布代码({% url ... %} 模板标签所在的位置,或者可能来自您配置成功 URL 的视图。

    【讨论】:

      猜你喜欢
      • 2018-12-17
      • 2023-03-28
      • 2020-02-10
      • 2017-05-24
      • 2017-10-10
      • 1970-01-01
      • 1970-01-01
      • 2014-07-17
      • 2020-11-18
      相关资源
      最近更新 更多