Seb*_* B. 10 django django-templates django-allauth
我正在使用Django 1.10,我想将allauth的应用程序添加到我的网站登录,登录等.我从pip安装了allauth,并试图将allauth存储库中的模板放在我的模板文件夹中并调用它们,但我不知道如何使其工作.
Tit*_*ter 20
可在此处找到正确答案:https://stackoverflow.com/a/31282443/4992248
yourproject/templates/allauth/account/
在此处创建并粘贴您需要编辑的所有模板/myproject/Lib/site-packages/allauth/templates/account
.如果您需要对socialaccount
模板进行更改,请同时创建yourproject/templates/allauth/socialaccount/
'DIRS'
在settings.py
像'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',
],
},
},
]
Run Code Online (Sandbox Code Playgroud)
/Lib/site-packages/*
,因为更新包后所有更改都将丢失.似乎该模块的文档已过时.对于Django 1.10,您应该执行以下操作:
'django.contrib.sites', # first place
'allauth', # after your modules declarations
'allauth.account',
'allauth.socialaccount',
Run Code Online (Sandbox Code Playgroud)
Run Code Online (Sandbox Code Playgroud)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).您可以使用"pip freeze"命令验证模块版本.
创建一个人工模块来覆盖模板; 例如,我的项目名为irj_app,我添加了一个名为_shared的新应用程序,然后我有以下结构,并在'allauth'声明之前将其添加到INSTALLED_APPS:
irj_app / _shared
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)
希望能帮助到你
尝试这个:
在应用程序的模板目录中创建帐户目录,如下所示
yourppname/模板/帐户
和文件
yourppname/templates/account/login.html
yourppname/templates/account/signup.html
并将下面添加到您的模板目录记住将您的应用名称更改为您的应用名称
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',
],
},
},
]
Run Code Online (Sandbox Code Playgroud)
小智 5
这对我使用 Django 2.1.7 和 django-allauth 0.39.1 有效:
在文件夹中yourapp/templates/
创建一个名为account
so的文件夹,结构是yourapp/templates/account/
并添加所有要覆盖的模板,如login.html
或signup.html
。
在settings.py
我的模板目录中保持不变
'DIRS': [os.path.join(BASE_DIR, 'templates')],
归档时间: |
|
查看次数: |
7638 次 |
最近记录: |