django Custom Template is not rendering for password_change_form.html

Viewed 907

I have a password_change_form.html which is custom formatted on the website. I'm overriding the Django default template with my template. But, it is not rendering my template. It just rendering the default template as below.

enter image description here

I have created a custom formated template

base.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

{% 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

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

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.

1 Answers

The solution for me was to point the "users" app above the built-in django apps in "INSTALLED_APPS = []".

upd 11/12/2020:

Python reads the code from top to bottom.

From Django official docs on INSTALLED_APPS settings:

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.

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

Therefore, the "users" app must go before the admin application in INSTALLED_APPS.

Related