Django AllAuth does not extend 'base.html', despite base.html existing in templates

Viewed 332

base.html works for all other url links, but as soon as I load localhost:8000/accounts/ (e.g. logout or login), the css template does not work at all. The functionality still works, it's just the css that isn't working.

This is as per the tutorial (From 8:22 to 10:44): https://www.youtube.com/watch?v=bopkZBbIa7c. I have followed the tutorial step by step, yet it gives a different result than the tutorial. (Just want to reiterate the functionality is fine, just plain django css)

My current settings.py is:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'tinymce',
    'posts',

    'django.contrib.sites',

    'allauth',
    'allauth.account',
    'allauth.socialaccount',
]

Urls:

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', index),
    path('blog/', blog, name='post_list'),
    path('post/<id>', post, name = 'post_detail'),
    path('search/', search, name = 'search'),
    path('tinymce/', include('tinymce.urls')),
    path('accounts/', include('allauth.urls')),
    path('accounts/profile/', blog, name='post_list')
]

Any help would be appreciated. Thanks.

Django version 3.1.4 Python 3

1 Answers

1. The cause: allauth's login.html is using its own base.html.

Django will look for allauth's login.html in allauth package. You can inspect that under

myvenv/lib/python3.7/site-packages/allauth/templates/account/login.html

The template under this folder will use base.html of allauth's located at:

myvenv/lib/python3.7/site-packages/allauth/templates/

not the one you created under /templates.

2. How to force allauth's login.html to use your own base.html?

I assume that

  • a. you have already made a project-wise templates folder.
  • b. under settings.py, you have this under TEMPLATES=[
        'DIRS': [BASE_DIR.joinpath('templates')],
        'APP_DIRS': True,

Then, you will generate a folder called account and put login.html in it.

templates/account/login.html

Now, when django looks for template login.html, it will first look into templates/account/login.html rather than allauth package's template. In this case, the template will use your own base.html.

Related