【发布时间】:2017-10-13 05:55:01
【问题描述】:
我不明白为什么我的 django-allauth 模板无法呈现。我将 allauth 目录复制到我的项目中。我还有一个以引导程序为主题的目录应用程序,应该在登录后显示。我希望显示来自 django-allauth 的注册和登录表单,登录后随后重定向到呈现引导主题的目录应用程序模板。
在 settings.py 以及其他必需的应用程序中,我在 INSTALLED_APPS 中的目录应用程序之后添加了 django-allauth 模块。
INSTALLED_APPS=['catalog',
'allauth',
'allauth.account',
'allauth.socialaccount',
]
将身份验证后端添加为:
AUTHENTICATION_BACKENDS = (
# Needed to login by username in Django admin, regardless of `allauth`
"django.contrib.auth.backends.ModelBackend",
# `allauth` specific authentication methods, such as login by e-mail
"allauth.account.auth_backends.AuthenticationBackend"
)
在 settings.py 中,templates 目录设置为:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR,'allauth/templates/account'),os.path.join(BASE_DIR,'catalog/templates/catalog')],
'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',
'allauth.account.contextprocessors.account',
'allauth.socialaccount.contextprocessors.socialaccount',
'django.template.context_processors.debug',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'ecomstore.utils.context_processors.ecomstore',
],
},
},
]
我让 django-allauth 登录成功时路由到哪个 url。添加LOGIN_REDIRECT_URL = '/'
将myproject中的url路由设置为:
urlpatterns = [
url(r'^accounts/', include('allauth.urls')),
]
如上所述,我的问题是为什么没有渲染 django-allauth 模板?
【问题讨论】:
-
你能显示错误吗?
-
@AstikAnand 没有“错误”消息,除了显示的模板应该是来自 django-allauth 的登录和注册表单,而不是源自目录应用程序的项目(引导)模板。
-
也许模板名称冲突尝试更改项目的模板名称。
标签: django twitter-bootstrap templates django-allauth