Django-allauth is loading the wrong base.html template

I try to get django-allauth by working a couple of days and finally find out what is going on.

Instead of downloading the base.html template that is installed with django-allauth, the application 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 instead of my project/template directory?

+8
source share
6 answers

If you call directly, your base.html is an extension of the templates you define.

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

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

It is best to copy the django-allauth base.html base.html to a specific location TEMPLATE_DIRS , rename it to allauthbase.html , and then expand the templates to include it instead of the default database via {% extends "allauthbase.html" %} .

Alternatively, you can add a subfolder to your template location, for example project/template/allauth , place allauth base.html , and then use {% extends "allauth/base.html" %} .

+7
source

Two years later, this continues to be a problem, and there is no new information in the accepted answer.

On github, I found that all allauth templates come from account / base.html, which comes 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' %} )
  • Delete allauth base.html . Now it is redundant.

Done!

+3
source

All of the answers provided force you to rewrite files and modify your own project to fit Allah, which is an absolutely unacceptable workflow. Such a third-party application should not have such manipulative power over your own project.

Indeed, the easiest way to handle this situation, especially based on the answers provided, is simply to move the allauth application and its associated applications to the end of the INSTALLED_APPS list in the settings.py file. Django will find your base.html template before it finds another base.html template in the other applications listed below.

The problem is solved.

+2
source

django-allauth templates seem to extend account/base.html ( example ), which extends base.html .

So copy base.html , for example, myapp/templates/account/base.html , and make sure myapp loads before django-allauth (by placing it higher in INSTALLED_APPS ).

Now django auth templates will expand your account/base.html , which will be django-allauth base.html .

This is not ideal since django-allauth base.html may be updated and you will skip these updates. But this seems better than renaming all your imports or modifying django-allauth .

Note that you can also just put {% block content %} in your base.html around the content, and then django-allauth will use this style, which in many cases seems good.

+1
source

Allauth trying to extend myproject/templates/base.html . The easiest way is to move base.html to myproject/templates/site/ to get myproject/templates/site/base.html or just rename base.html

+1
source

I had the opposite problem: I tried to use my own base.html file, but my Django project was capturing the django-allauth version of base.html . It turns out that the order you define INSTALLED_APPS in settings.py affects the way the templates are displayed. To make my base.html render instead of the one defined in django-allauth , I needed to define INSTALLED_APPS as follows:

 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'), ] 
0
source

Source: https://habr.com/ru/post/944896/


All Articles