我不明白为什么我的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 = [
{
'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模板没有呈现?
发布于 2018-04-23 18:27:08
您缺少了一些东西:在INSTALLED_APPS中:
'django.contrib.sites',在此之后添加一行
SITE_ID = 1如果当你把这些放进去的时候,它仍然不起作用,那么应用程序的加载顺序可能会出现问题。
Allauth还附带了自己的登录、注销和更改密码(请参阅这里 )。
如果要切换模板,可以使用以下标记将这些模板放入其中:
{% url 'account_login' %} <!-- Sign In-->如果需要检查用户是否已登录,则可以使用if语句。
{% if user.is_active %} <!-- checks if user signed in-->
<!-- Insert code here that appears if signed in-->
{% else%}
<!-- Insert code here to display for users that did not sign in-->
{% endif%}最后,如果需要对模板进行样式设计,可以找到这里。但是,您需要创建一个accounts文件夹,并将它们放在其中以覆盖默认的帐户文件夹。
https://stackoverflow.com/questions/43962685
复制相似问题