首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >升级Django和allauth,返回/ KeyError /KeyError/

升级Django和allauth,返回/ KeyError /KeyError/
EN

Stack Overflow用户
提问于 2016-02-14 03:19:35
回答 1查看 385关注 0票数 4

我从Django 1.7.1升级到1.9,同时也升级了allauth。在升级之后,我不得不修复很多but,但这一次我被卡住了。除了provider_login_url之外,一切都正常。如果我从模板中删除url,它会正常呈现,但我无法链接到url...

错误:

代码语言:javascript
复制
KeyError at /accounts/profile/

Django Version: 1.9.2
Exception Type: KeyError
Exception Value:    
'facebook'
/allauth/socialaccount/providers/__init__.py in by_id, line 20

Error during template rendering
allauth/templates/account/profile.html, error at line 68

68 .. <a href="{% provider_login_url "facebook" process="connect" %}" class="edit_profile_link">Connect this account with my Facebook account</a>

视图:

代码语言:javascript
复制
def profile(request):
    return render_to_response("account/profile.html",locals(),context_instance=RequestContext(request))
EN

回答 1

Stack Overflow用户

发布于 2016-12-03 01:37:57

在配置文件模板中,确保您有

代码语言:javascript
复制
{% load socialaccount %}

在设置中,确保您有

代码语言:javascript
复制
INSTALLED_APPS = (
  'allauth',
  'allauth.account',
  'allauth.socialaccount',
  'allauth.socialaccount.providers.facebook',
  ...
)

“facebook”的KeyError很可能是上面的facebook提供商丢失的结果。

由于您从1.7升级了应用程序,因此请确保在以下设置中更改请求上下文处理器

代码语言:javascript
复制
TEMPLATE_CONTEXT_PROCESSORS = (
    ...
    # Required by `allauth` template tags
    'django.core.context_processors.request',
    ...
)

代码语言:javascript
复制
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                # Already defined Django-related contexts here

                # `allauth` needs this from django
                'django.template.context_processors.request',
            ],
        },
    },
]
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35384287

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档