django - 升级 Django 和 allauth 返回 KeyError at/accounts/profile/

标签 django upgrade init django-allauth keyerror

我从 Django 1.7.1 升级到 1.9,同时升级了 allauth。升级后我必须修复许多错误,但在这个问题上我陷入了困境。一切正常,但provider_login_url..如果我从模板中删除网址,它会正常呈现,但我无法链接到该网址...

错误:

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))

最佳答案

在个人资料模板中,确保您有

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

关于django - 升级 Django 和 allauth 返回 KeyError at/accounts/profile/,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35384287/

相关文章:

Django Admin'页面未在/admin/中找到

c# - 框架升级到 3.5

c# - 升级 ASP.NET MVC 2 项目后,如何在 System.Web.dll 中查找 StackOverflowException 的原因?

asp.net - 子Page_Init方法: Event init cannot be found

python - 访问 django 中 n-uplet 的列的值

django - 在 Django Rest Framework 中使用 PUT 更新外键

javascript - 为什么名为 'index.js' 的 JavaScript 文件在 Django 模板中不起作用?

hibernate - 如何升级 Hibernate 4.3 --> 5.2?

swift - 从 Storyboard启动的初始应用程序无法调用 NSDocument init

.net - 使用启动脚本运行 `Unhandled Exception: System.ArgumentNullException: Value cannot be null.` 时出现 `dotnet run` 错误