我几周/几个月前曾在社交服务提供商工作,但它已经不再适用了。我检查了文档但仍然不知道我错过了什么。我认为在将django升级到1.8(在settings.py中改变了模板上下文处理器,...)之后它停止了工作。我有google,facebook和twitter工作。
这是关于allauth的settings.py:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
# insert your TEMPLATE_DIRS here
os.path.join(PROJECT_DIR, 'templates'),
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
"django.contrib.auth.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.static",
"django.core.context_processors.tz",
"django.contrib.messages.context_processors.messages",
# Required by allauth template tags
'django.template.context_processors.request',
#controller context processors (portfolios)
"controller.context_processors.portfolio_processor",
],
},
},
]
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",
)
#allauth settings
ACCOUNT_AUTHENTICATION_METHOD = "username_email"
ACCOUNT_EMAIL_CONFIRMATION_EXPIRE_DAYS = 7
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_VERIFICATION = "mandatory"
ACCOUNT_UNIQUE_EMAIL = True
ACCOUNT_USERNAME_MIN_LENGTH = 3
ACCOUNT_PASSWORD_MIN_LENGTH = 5
LOGIN_REDIRECT_URL = "/"
SOCIALACCOUNT_PROVIDERS = \
{
'facebook':
{'SCOPE': ['email', 'publish_stream'],
'AUTH_PARAMS': {'auth_type': 'reauthenticate'},
'METHOD': 'oauth2',
'LOCALE_FUNC': lambda request: 'en_US',
'VERIFIED_EMAIL': False},
'google':
{ 'SCOPE': ['profile', 'email'],
'AUTH_PARAMS': { 'access_type': 'online' } }
}
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.humanize',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
#library folder
'lib',
#extra apps
'django_crontab',
#search
'haystack',
#apps
'stocks',
'portfolio',
'watcher',
'suggestion',
#'broker',
#allauth
'allauth',
'allauth.account',
'allauth.socialaccount',
'loginas',
#allauth providers
'allauth.socialaccount.providers.facebook',
'allauth.socialaccount.providers.google',
'allauth.socialaccount.providers.twitter',
#bootstrap
'bootstrap3',
'bootstrap3_datetime',
#admin
'django.contrib.admin.apps.SimpleAdminConfig',
#'django.contrib.admin',
#'django.contrib.admindocs',
'debug_toolbar',
)
在cource中我已经在社交应用程序中设置了twitter,facebook和google 在login.html中,我包含了这样的提供者:
{% if socialaccount.providers %}
<div class="col-md-5 col-lg-5">
<!--
This is the raw "real" HTML that facebook recommends.
Leaving here for reference.
<div class="fb-login-button" data-max-rows="1" data-size="large" data-show-faces="false" data-auto-logout-link="false"></div>
-->
<div class="socialaccount_ballot">
<ul class="socialaccount_providers list-unstyled">
{% include "socialaccount/snippets/provider_list.html" with process="login" %}
</ul>
<div class="login-or" style="text-align: center">{% trans 'or' %}</div>
</div>
{% include "socialaccount/snippets/login_extra.html" %}
</div>
{% endif %}
然后在socialaccount/snippets/provider_list.html
:
{% load socialaccount %}
{% for provider in socialaccount.providers %}
{% if provider.id == "openid" %}
{% for brand in provider.get_brands %}
<li>
<a title="{{brand.name}}"
class="socialaccount_provider {{provider.id}} {{brand.id}}"
href="{% provider_login_url provider.id openid=brand.openid_url process=process %}"
>{{brand.name}}</a>
</li>
{% endfor %}
{% endif %}
<li style="text-align: center;">
<a title="{{provider.name}}" class="socialaccount_provider {{provider.id}}"
href="{% provider_login_url provider.id process=process scope=scope auth_params=auth_params %}">{{provider.name}}</a>
</li>
{% endfor %}
当我尝试打印soccialaccount时,它是空白/无:
{% load socialaccount %}
{{socialaccount}}
我错过了什么?我使用的是django 1.8和allauth = 0.23。
答案 0 :(得分:2)
从0.21开始有变化,所以检查当你做什么时会发生什么
{% get_providers as socialaccount_providers %}
{{ socialaccount_providers }}