1
votes

I'm using the django built-in function to reset the password in case the user forgot his password.

I also created my own Html pages to make the appearance look good.

password_reset_form.html, password_reset_done.html, password_reset_confirm.html, password_reset_complete.html, and password_reset_email.html for the email.

  1. the name of password_reset_form.html in my URL is "reset_password"\
  2. the name of password_reset_done.html in my URL is "password_reset_done"\
  3. the name of password_reset_confirm.html in my URL is "password_reset_done"\
  4. the name of password_reset_complete.html in my URL is "password_reset_complete"

reset_password and password_reset_done django inbuilt templates work well with my html page created.

The problem apprears When I clicked on the link sent to my e-mail, I should see back to my browser my custom url page (password_reset_confirm.html) but instead i'm seeing the django built in template ("password reset confirmation").

I don't know where is the mistake. I have been trying to set that for 2 days now, but it's difficult to figure it out.

Can you please help me out?

here is my setting:

"""
Django settings for grouppublishingindia project.

Generated by 'django-admin startproject' using Django 3.1.1.

For more information on this file, see
https://docs.djangoproject.com/en/3.1/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/
"""
import os
from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
TEMPLATE_DIR = os.path.join(BASE_DIR,'templates')


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '5r0zcv0wdd2yhow_t)k)xj$c(3mnkqiww_yr0w7k+i+ii36)5v'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'Inventory',
    'crispy_forms',
    'debug_toolbar',
    'import_export',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'debug_toolbar.middleware.DebugToolbarMiddleware'
]

CRISPY_TEMPLATE_PACK = "bootstrap4"

ROOT_URLCONF = 'grouppublishingindia.urls'


TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS':  [os.path.join(BASE_DIR, 'Inventory', 'templates')],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'grouppublishingindia.wsgi.application'


# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}


# Password validation
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/3.1/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/

STATIC_URL = '/static/'
LOGIN_REDIRECT_URL = "contenu"

#SMTP (Simple Mail Transfert Protcole) Configuration

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = '*******************'
EMAIL_HOST_PASSWORD = '***************'

here is my project URLs:

from django.urls import path, include
from django.contrib.auth import views as auth_views
from django.conf.urls import url
from django.contrib import admin
from django.conf import settings
from Inventory import views

urlpatterns = [
    path('admin/', admin.site.urls),
    path("",include("Inventory.urls")),
    url('Inventory/',include('django.contrib.auth.urls')),    
]

here is my app URLs:

from django.contrib.auth import views as auth_views
from django.urls import reverse
from django.conf.urls import url
from .views import *
from Inventory import views
from .views import index
from Inventory.views import SearchResultsView
from django.urls import path


app_name = "Inventory"

urlpatterns =[

    path('password_reset/', auth_views.PasswordResetView.as_view(template_name='Inventory/password_reset_form.html',
          success_url=reverse_lazy('Inventory:password_reset_done')),name="reset_password"
         ),

    path('password_reset/done/',
          auth_views.PasswordResetDoneView.as_view(template_name='Inventory/password_reset_done.html'), name="password_reset_done"
         ),

    path('password_reset_confirm/<uidb64>/<token>/',
          auth_views.PasswordResetConfirmView.as_view(template_name='Inventory/password_reset_confirm.html'),
          name="password_reset_confirm"
         ),

    path('reset_password_complete/',
          auth_views.PasswordResetCompleteView.as_view(template_name='Inventory/password_reset_complete.html'),
          name="password_reset_complete"
         ),
]
1
again try after renaming the url name from password_reset_confirm to password_reset_confirmation. becuase the password_reset_comfirm might be used as name for django's built-in url.Ajay Lingayat
@AjayLingayat, Thank you for your quick response, I tried, but it still doesn't workLeo
@Ajay Lingayat, I found the answer, by going through once again. The mistake was located in the Main URL path(project url). I didn't put my custom html URLs in a main project url path. so I changed the path, then i got the result i was expected. I mentioned where was located the mistake in case my response can help someone. :)Leo

1 Answers

0
votes

The cause of your problem is the way Django's default template loader discovers templates. It will look in the templates subdirectory of each of your INSTALLED_APPS and use the first template with the specified name. This means your app ordering is important. From the above link:

The order of INSTALLED_APPS is significant! For example, if you want to customize the Django admin, you might choose to override the standard admin/base_site.html template, from django.contrib.admin, with your own admin/base_site.html in myproject.polls. You must then make sure that your myproject.polls comes before django.contrib.admin in INSTALLED_APPS, otherwise django.contrib.admin’s will be loaded first and yours will be ignored.

So, the solution is to move django.contrib.admin (which supplies the default password_reset_*.html templates) from the top to the bottom of your INSTALLED_APPS:

INSTALLED_APPS = [
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'Inventory',
    'crispy_forms',
    'debug_toolbar',
    'import_export',
    'django.contrib.admin',
]

Or, depending on your taste, move your own app to the top :-)