Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django-allauth loads wrong base.html template

I've been trying to get django-allauth working for a couple days now and I finally found out what was going on.

Instead of loading the base.html template that installs with django-allauth, the app loads the base.html file that I use for the rest of my website.

How do i tell django-allauth to use the base.html template in the virtualenv/lib/python2.7/sitepackages/django-allauth directory instead of my project/template directory?

like image 501
bcoop713 Avatar asked May 13 '13 15:05

bcoop713


3 Answers

I had the opposite problem: I was trying to use my own base.html file, but my Django project was grabbing the django-allauth version of base.html. It turns out that the order you define INSTALLED_APPS in settings.py affects how templates are rendered. In order to have my base.html render instead of the one defined in django-allauth, I needed to define INSTALLED_APPS as the following:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # custom
    'common',
    'users',
    'app',
    # allauth
    'django.contrib.sites',
    'allauth',
    'allauth.account',
    'allauth.socialaccount',
]

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static'),
]
like image 125
cjohnson318 Avatar answered Nov 09 '22 04:11

cjohnson318


Unless called directly, your base.html is an extension of the templates that you define.

For example, if you render a template called Page.html - at the top you will have {% extends "base.html" %}.

When defined as above, base.html is located in the path that you defined in your settings.py under TEMPLATE_DIRS = () - which, from your description, is defined as project/template.

Your best bet is to copy the django-allauth base.html file to the defined TEMPLATE_DIRS location, rename it to allauthbase.html, then extend your templates to include it instead of your default base via {% extends "allauthbase.html" %}.

Alternatively you could add a subfolder to your template location like project/template/allauth, place the allauth base.html there, and then use {% extends "allauth/base.html" %}.

like image 37
Dan Hoerst Avatar answered Nov 09 '22 03:11

Dan Hoerst


Two years later this continues to be a problem and the accepted answer is missing some new information.

On github I discovered that all allauth templates derive from account/base.html, which derives from base.html. My solution was:

  • In virtualenv/lib/python2.7/sitepackages/django-allauth/templates, copy the entire contents of base.html to replace everything in account/base.html (i.e. replace the {% extends 'base.html' %} statement)
  • Delete allauth's base.html. It is now redundant.

Done!

like image 24
gatlanticus Avatar answered Nov 09 '22 03:11

gatlanticus