1
votes

enter image description hereI am working on rest password via custum templates in django,but custom template not loading it is loading django's default template every time i load the /password_reset/ url.

I am using the url

 url('^', include('django.contrib.auth.urls')),

i have a registration folder in templates and using this link to work https://simpleisbetterthancomplex.com/tutorial/2016/09/19/how-to-create-password-reset-view.html

and the template folder is:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
                 ],

        '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',
                "cms.utils.context_processors.permission_based_hidding_of_sidebar",
            ],
            'libraries':{
                'template_tag': 'cms.templatetags.template_tag',
                'template_tag_time': 'cms.templatetags.tags',
            }
        },
    },
]

install apps in settings:-

INSTALLED_APPS = [
    'cms',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django_extensions',
    'django_csv_exports',
    'django.contrib.auth',
    'django.contrib.admin',


]
3
Did you created password_reset template files in your directory?Raja Simon
yes i have a registration folder in my templates where i have created password_reset.html templatesAbi Waqas
Can you include your project structure in your question? I also want to know that where is your registration folder ?Raja Simon
just uploaded my project structure with settings.py is there and at the bottom of templates registration folder where i have all the templatesAbi Waqas
'DIRS': [os.path.dirname(os.path.dirname(os.path.abspath(file))) You should refer to the template directory path --------> 'DIRS': [os.path.dirname(os.path.dirname(os.path.abspath(file)), 'templates')hadi

3 Answers

1
votes

See my comment below. Sure, you can hack it and remove the form in the distribution library. Very very naughty. A much better solution is to alter the order in which the apps are loaded in your settings file. Originally I had:

INSTALLED_APPS = ['django.contrib.auth', 'ana_access',]

I just changed this so my app loaded first. And lo. That did it.

INSTALLED_APPS = ['ana_access','django.contrib.auth', ]

Conclusion: if you keep seeing the default page DESPITE having the form in your templates/registration folder, then it might be because you are loading the default django.contrib.auth app before your own.

0
votes

If you want to override the Django admin template you need to created admin folder inside your templates directory. And place all your admin's files and folders there...

templates
|__ admin
    |__ registration

Update: Also please correct the TEMPLATES DIR It should be

'DIRS': [os.path.join(BASE_DIR, 'templates')],
0
votes

Django 3.0. 2020. I solved the issue by adding template/registration/*.html in the project directory. This solved my issue. I don't need to change anything in the INSTALLED_APPS list.

Here are the steps:

  1. Do the following highlighted changes in "settings.py"
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')], # **ADD THIS
        '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',
                'django.template.context_processors.media',
                'django.template.context_processors.static', # * (optional)
            ],
        },
    },
]
  1. Create templates/registration directories in your project root folder and add your registration templates here instead of your_app/templates/registration.
Project_root_folder/templetes/registration/*.html

No need to change anything in INSTALLED_APPS of settings.py