It's quite easy once you know Django's template look up order and you configure the TEMPLATE =[]
properly as per your need. There's no need to play with views or Python code if it's just about overriding allauth's templates.
Let's understand the Django's template look up order at first, just a little. Django's template lookup order is as follows, all of these are configured inside TEMPLATE =[]
in project's settings.py.
I. 'Loader'
: Give you the option to use Template Loaders which are responsible for locating templates, loading them, and returning Template objects. General implementations don't use it much. If you haven't configured a template loader then one of the following two option would decide which template is used by your view.
II. 'DIRS'
: Here you get the option to explicitly tell Django where to search for templates, in order, up to down.
III. 'APP_DIRS'
: If this field is set to true then Django looks for your template in your apps' dir. To correctly use this option you need to organize your templates as follows:
root_dir
app1_dir
templates
your_template.html
app2_dir
templates
your_template.html
You must name your templates dir as "templates" and you must put your templates in that dir only for this to work
Third option is little weird though, if a template in your app's view isn't found in corresponding app's template dir Django will go through template dir of other apps to find it.
It works well if templates are organized properly and naming convention of templates is standardized, so that when a template isn't found in local app's dir, that template shouldn't be erroneously found in other app's dir. Well, you may have some scenarios where you would want it to work that way.
Now, to the point answer to your question:
Allauth by default uses the templates from:
Python installed directory or virtual env --> *Lib --> site-packages --> allauth --> templates*
You would usually want to override all the allauth's templates as they are very basic and you would want to beautify/modify them all, following are the steps which would enable you to override them all, if you don't wish to override all of them do as follows, but just don't change the HTML for that template, simple!
Suppose your project structure is as follows:
projectdir
app1_dir
app2_dir
projectname_dir
Copy the templates dir from Python installed directory or virtual env --> Lib --> site-packages --> allauth --> templates
to a dir of your choice, suppose you chose to keep it in app1_dir (you may chose any dir, makes no difference, but you should choose an appropriate one as per your requirements), then create a dir in app1_dir named 'allauth' (you could name it anything you like), then paste the copied allauth's templates dir in this dir, so now your project structure would look as follows:
projectdir
app1_dir
allauth
templates
account
openid
socialaccount
base.html
app2_dir
projectname_dir
Change your TEMPLATES = []
in project settings as follows:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'allauth', 'templates'),
],
'APP_DIRS': True,
},
]
Here BASE_DIR is projectdir (root dir)
Basically you may keep the copied template dir from allauth dir in any project's dir of your choice, but you must enusre that you provided the correct path here:
'DIRS': [os.path.join(BASE_DIR, 'allauth', 'templates')
If it doesn't work then, set 'APP_DIRS': False
, then you would see a debug message from Django and it wouldn't use app dir (allauth dir in site-packages). And then looking at that error you may figure out what's wrong with your config.