How to edit django-allauth default templates?

I am using Django 1.10 and I want to add an allauth application for login, login, etc. to my site. I installed allauth from pip and tried to put the templates from the allauth repository into the templates folder and call them, but I don't know how to make it work.

+4
source share
5 answers

The correct answer can be found here: fooobar.com/questions/207873 / ...

  • Create yourproject/templates/allauth/account/and paste here all the templates you need to edit from /myproject/Lib/site-packages/allauth/templates/account.

If you need to make changes for templates socialaccount, create alsoyourproject/templates/allauth/socialaccount/

  1. Change 'DIRS'to settings.pyhow'DIRS': [os.path.join(BASE_DIR, 'templates'), os.path.join(BASE_DIR, 'templates', 'allauth')],

:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates'), os.path.join(BASE_DIR, 'templates', 'allauth')],
        'APP_DIRS': True,
        'OPTIONS': {
            'debug': False,
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.template.context_processors.media',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]
  1. /Lib/site-packages/*, .
+10

, . Django 1.10 :

  • pip
  • INSTALLED_APPS (/settings.py)

'django.contrib.sites', # first place
'allauth',  # after your modules declarations
'allauth.account',
'allauth.socialaccount',
  • backend , allauth
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'allauth.account.auth_backends.AuthenticationBackend',
)
SITE_ID = 1
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_USERNAME_REQUIRED = True
  • , django 1.10 TEMPLATES (django-allauth == 0.28.0). " ".

  • ; , irj_app, _shared, INSTALLED_APPS allauth:

irj_app / _shared

  • "_shared", "base.html", allauth. , django-allauth , , , django-allauth, . . , :

irj_app / _shared / templates / base.html

irj_app / _shared / templates / account / base.html

irj_app / _shared / templates / account / signup.html

irj_app / _shared / templates / _shared / adminlte-template / ... (template for other modules)

,

+6

:

account ,

yourppname//

yourppname///login.html

yourppname///signup.html

TEMPLATE DIRS yourappname

os.path.join(BASE_DIR, 'yourappname', 'templates')

TEMPLATES = [
{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [os.path.join(BASE_DIR, 'yourappname', 'templates')],
    'APP_DIRS': True,
    'OPTIONS': {
        'context_processors': [
            'django.template.context_processors.debug',
            'django.template.context_processors.request',
            'django.contrib.auth.context_processors.auth',
            'django.contrib.messages.context_processors.messages',
        ],
    },
},
]
+1

Allauth , .

TEMPLATE_DIRS = ( os.path.join(BASE_DIR,'templates'), os.path.join(BASE_DIR,'templates'))

  1. . create a directory named allauth, inside allauth create a template directory and inside that create a directory accounts

  2. html , allauth-. allauth github repository.

0

, .

, , , ( env):

Envs/myproject/Lib/site-packages/allauth/templates

i changed base.html and added my static folder with all bootstrap and jquery files to the settings in the file:

app_settings.py

and added that.

...
import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

STATIC_URL = '/static/'

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static"),
]

And that’s all.

I don't know if this is a propper way, but if anyone has a better answer, post it.

-2
source

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


All Articles