Django-two-factor-auth library requires a _base.html file to customize the styling for integration.
I need the base for my login page to be different to that of the other two factor pages. How can I use two different _base.html files instead of using the same _base.html for all the two factor urls?
in your project directory, add a folder called
templates
, same level as your apps such asusers
,blogs
, etc. Inside of it, create another folder fortwo_factor
. Inside of this folder, put your modifiedbase.html
.If somehow you get error message, in your
settings.py
underTEMPLATES = [
. Replacewith
or
Here is Doc about templates
Update after op's own answer
If you want to have
two_factor/templates/two_factor/core/login.html
use your ownbase.html
, you should follow what I mentioned above, you will havetemplates/two_factor/core/login.html
. Note thattemplates
is in the same directory level as your otherapps
. In thetemplates
folder, generatetwo_factor
folder, then inside of it, generatecore
folder, then inside of that generatelogin.html
. You can now modify it whichever you want to.The reason that you want to override but not change things in the package directory is because when you update your package you have to make the changes again manually.
The reason that the approach above works is since we put
'DIRS': [os.path.join(BASE_DIR, 'templates')]
in settings, Django will look for this folder first for templates. The detailed application of this method is here Overriding from the project’s templates directory