2016-02-13 29 views
2

我从Django 1.7.1升级到1.9,并且我同时升级了allauth。升级后,我不得不修复许多错误,但这个我卡住了。一切工作,但provider_login_url ..如果我删除它通常呈现范本中的网址,但我不能链接到网址...升级Django和allauth返回KeyError at/accounts/profile/

错误:

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> 

观点:

def profile(request): 
    return render_to_response("account/profile.html",locals(),context_instance=RequestContext(request)) 
+0

你可能想尝试遍历'{%get_providers作为socialaccount_providers%}'看看facebook是否是一个选项。 – Sayse

+0

如果我使用{%get_providers as socialaccount_providers%}我得到以下错误:第6行上的无效块标记:'get_providers'。你忘了注册或加载这个标签吗? – Torostar

+0

你的“account/profile.html”里有什么? –

回答

0

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

{% load socialaccount %} 

在设置中,请确保您有

INSTALLED_APPS = (
    'allauth', 
    'allauth.account', 
    'allauth.socialaccount', 
    'allauth.socialaccount.providers.facebook', 
    ... 
) 

的'Facebook的该KeyError异常是由缺少上述Facebook的供应商有可能的结果。

而且因为你升级1.7的应用程序,确保在设置里更改请求上下文处理器从

TEMPLATE_CONTEXT_PROCESSORS = (
    ... 
    # Required by `allauth` template tags 
    'django.core.context_processors.request', 
    ... 
) 

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', 
      ], 
     }, 
    }, 
]