1π
Go to the Django admin registration directory
/home/username/Desktop/Project_folder/virtual_env_name/lib/python3.6/site-packages/django/contrib/admin/templates
Now open the password_reset_form.html and replace the
{% extends "admin/base_site.html" %}
from the template, you want to extend. In my case, I do the following
{% extends "feed/base.html" %}
feed: app name
base.html: base file
23π
You can also make sure that your app comes before all other Django apps in INTALLED_APPS
e.g
INSTALLED_APPS = [
'your_app_name',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.sites',
'django.contrib.staticfiles',
]
replace your_app_name with the name of your app
5π
In your settings.py make sure your TEMPLATES settings is equal to the following
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, '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',
],
},
},]
the most important part here is the DIRS
- Difference between Response and HttpResponse django
- Django Override Admin change_form.html Template β display associated model in template
- Django NodeNotFoundError during migration
- Django β check if list contains something in a template
- Django: How to save original filename in FileField?
2π
I struggled with this for hours. I tried rewriting the admin template I thought against it so I didnβt have to rewrite it for every new project.
finally stumbled across the answer on a blog referencing the Django 2.1 docs: βhttp://discuss.hellowebapp.com/t/django-2-1-changes/618/4β.
The blog explains the changes to path formatting and views syntax.
FILE STRUCTURE
###`blog/templates/registration/reset_password_form.html`###
###`blog/templates/registration/reset_password_done.html`###
###`blog/templates/registration/reset_password_complete.html`###
###`blog/templates/registration/reset_password_confirm.html`###
C:.
ββββblog
β β admin.py
β β apps.py
β β forms.py
β β models.py
β β tests.py
β β urls.py
β β views.py
β β __init__.py
β β
β ββββmigrations
β β
β ββββstatic
β β ββββcss
β β β blog.css
β β β
β β ββββstatic
β β ββββimages
β β
β ββββtemplates <-------
β β β add_comment_to_post.html
β β β
β β ββββblog
β β β base.html
β β β postDraftlist.html
β β β postEdit.html
β β β postsDetail.html
β β β postsList.html
β β β
β β ββββregistration <-------
β β home.html
β β login.html
β β password_reset_complete.htm <---
β β password_reset_confirm.html <---
β β password_reset_done.html <---
β β password_reset_form.html <---
β β
β ββββ__pycache__
ββββblogApp
β β settings.py
β β urls.py
β β wsgi.py
β β __init__.py
β β
β ββββ__pycache__
β
ββββsent_emails
|
β___.gitignore
β___db.sqlite3
β___manage.py
β
.
from django.contrib import admin
from django.urls import path, include
from django.views.generic.base import TemplateView
from django.contrib.auth.views import PasswordResetView, PasswordResetDoneView, PasswordResetConfirmView, PasswordResetCompleteView
urlpatterns = [
path('admin/', admin.site.urls),
#127.0.0.1:8000
path('', include('blog.urls')),
path('accounts/', include('django.contrib.auth.urls')),
path('', TemplateView.as_view(template_name='home.html'), name='home'),
path('accounts/password/reset/', PasswordResetView.as_view(template_name='registration/password_reset_form.html'), name='password_reset'),
path('accounts/password/reset/', PasswordResetDoneView.as_view(template_name='registration/password_reset_done.html'), name='password_reset_done'),
path('accounts/password/reset/', PasswordResetConfirmView.as_view(template_name='registration/password_reset_confirm.html'), name='password_reset_confirm'),
path('accounts/password/reset/', PasswordResetCompleteView.as_view(template_name='registration/password_reset_comlete.html'), name='password_reset_complete'),
SETTINGS
INSTALLED_APPS = [
'blog', #<--name of your app should go here at the top of this stack not bottom
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
So:
- file structure:
templates/registration/password_reset_form.html
urls.py
: imports and pathssettings.py
: INSTALLED_APPS and DIRS
- What is a good Django workflow?
- Using python string formatting in a django template
- AttributeError: 'NoneType' object has no attribute 'attname' (Django)
- In the Django REST framework, how are the default permission classes combined with per-view(set) ones?
- Found another file with the destination path β where is that other file?
2π
To override the admin templates for a password reset, the folder structure needs to be following and remember to place the custom templates in templates/registration
directory.
ββββblog
β β admin.py
β β apps.py
β β forms.py
β β models.py
β β tests.py
β β urls.py
β β views.py
β β __init__.py
β β
β ββββmigrations
β β
β ββββstatic
β β ββββ...
β β
β ββββtemplates
β β β ...
β β β
β β ββββblog
β β β ...
β β β
β β ββββregistration <-------
β β home.html
β β login.html
| | password_reset_form.html <------
| | password_reset_email.html <------
β β password_reset_done.html <------
β β password_reset_confirm.html <------
β β password_reset_complete.html <------
And be sure to name the template as,
password_reset_form.html
password_reset_email.html
password_reset_done.html
password_reset_confirm.html
password_reset_complete.html
And urls.py
paths should look like,
from django.contrib.auth import views as auth_views
# and other imports ....
path(
'password_reset',
auth_views.PasswordResetView.as_view(template_name='registration/password_reset_form.html'),
name='password_reset'
),
...
1π
Use custom password reset templates in django 2 with path()
Based on @samschultz response:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['path/to/yor/templates/'], # Example: 'templates' or /myapp/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',
],
},
},
]
Please, pay attention to >>> βDIRSβ <<<.
Hope it helps.
- Invalid parameter server_name in /etc/nginx/sites-enabled/django
- Django's "dumpdata" or Postgres' "pg_dump"?
- Django- session cookies and sites on multiple ports
- How do I rebuild my django-mptt tree?
- Using MongoDB as our master database, should I use a separate graph database to implement relationships between entities?
1π
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['accounts/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',
],
},
},
]
Take note of the directory path inside βDIRSβ: []β¦By default, it is empty. Put 'accounts/templates/'
. Also the accounts is the name of the app, which I assumed that you used accounts
.
- How disable return of HTML error page with django rest framework?
- Fix Conflicting migrations detected in Django1.9
- The current URL, app/, didn't match any of these
1π
After trying all the attempts listed in this thread, I still couldnβt get it to work. However, by replacing my custom urls in my accounts app to the exact link it was displaying in the email; I managed to fix it.
#My original urls link:
'users/password_reset/<uidb64>/<token>/'
#working link
'users/reset/<uidb64>/<token>/'
- How to perform DB bitwise queries in Django?
- How to execute external script in the Django environment
- Best way to denormalize data in Django?
0π
Path of templates should be correct else it will not work. Below works for me.
βDIRSβ: [os.path.join(BASE_DIR, βprojects/templates/projectsβ)],
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'projects/templates/projects')],
'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',
],
},
},
]
0π
This worked for me, I included the full path name as my template name
from django.contrib.auth import views as auth_views
# and other imports ....
path(
'password_reset',
auth_views.PasswordResetView.as_view(template_name='feed/templates/registration/password_reset_form.html'),
name='password_reset'
),
...
- Django difference between clear() and delete()
- Django template tag: How to send next_page in {url auth_logout}?
- What method attributes are used in Django?
- Docker Alpine: Error loading MySQLdb module
- Clone an inherited django model instance