简体   繁体   English

django 自定义模板未呈现 password_change_form.html

[英]django Custom Template is not rendering for password_change_form.html

I have a password_change_form.html which is custom formatted on the website.我有一个在网站上自定义格式的 password_change_form.html。 I'm overriding the Django default template with my template.我用我的模板覆盖了 Django 默认模板。 But, it is not rendering my template.但是,它没有呈现我的模板。 It just rendering the default template as below.它只是呈现如下的默认模板。

在此处输入图像描述

I have created a custom formated template我创建了一个自定义格式化模板

base.html底座.html

<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
 <a class="dropdown-item" href="{% url 'password_change' %}">Change password</a>
<div class="dropdown-divider"></div>

password_change_form.html password_change_form.html

{% extends 'home/base.html' %}

{% block body %}
    <h2>
        Change password
    </h2>
    <form method="post">
        {% csrf_token %}
        {{ form.as_p }}
        <button type="submit" class="btn btn-primary">Change password</button>
    </form>
{% endblock %}

urls.py网址.py

from django.contrib import admin
from django.urls import path, include
from Shopping.cart import urls


urlpatterns = [
    path('', include('Shopping.cart.urls')),
    path('accounts/', include('django.contrib.auth.urls')),
    path('admin/', admin.site.urls),
]

I wanted to see my template overrides the Django default template我想看到我的模板覆盖了 Django 默认模板

Resolved I made a mistake that I placed my templates folder inside the app.解决了我将模板文件夹放在应用程序中的错误。 this was causing the problem.这是造成问题的原因。 Now I moved my template folder to the Project folder.现在我将我的模板文件夹移动到项目文件夹中。 Now everything working fine.现在一切正常。 Thank you.谢谢你。

The solution for me was to point the "users" app above the built-in django apps in "INSTALLED_APPS = []".我的解决方案是将“用户”应用程序指向“INSTALLED_APPS = []”中的内置 django 应用程序上方。

upd 11/12/2020: 2020 年 11 月 12 日更新:

Python reads the code from top to bottom. Python 从上到下读取代码。

From Django official docs on INSTALLED_APPS settings:来自 Django 官方文档关于 INSTALLED_APPS 设置:

When several applications provide different versions of the same resource (template, static file, management command, translation), the application listed first in INSTALLED_APPS has precedence.当多个应用程序提供相同资源(模板、static 文件、管理命令、翻译)的不同版本时,INSTALLED_APPS 中最先列出的应用程序具有优先权。

If the "users" app is located below 'django.contrib.admin', then Django will go to the "admin" application and find there templates/registration/password_change_form.html如果“用户”应用程序位于“django.contrib.admin”下方,则 Django 将 go 到“管理员”应用程序并找到模板/注册/密码_change_form.ZFC35FDC73A28FC69D23EZ8C

Therefore, the "users" app must go before the admin application in INSTALLED_APPS.因此,“用户”应用程序必须在 INSTALLED_APPS 中的管理应用程序之前 go。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM