Torostar
Torostar

Reputation: 497

upgrade Django and allauth returning KeyError at /accounts/profile/

I upgraded from Django 1.7.1 to 1.9 and I upgraded allauth at the same time. After the upgrade I had to fix many bugs but with this one I'm stuck. Everything is working but provider_login_url.. if I remove the url from the template it renders normally but I can't link to the url...

the error:

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>

views:

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

Upvotes: 4

Views: 485

Answers (1)

Shih-Wen Su
Shih-Wen Su

Reputation: 2689

In the profile template, make sure you have

{% load socialaccount %}

In the settings, make sure you have

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

The KeyError of 'facebook' is likely results from missing the facebook provider above.

And since you upgraded the app from 1.7, make sure to change your request context processors in the settings from

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

to

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

Upvotes: 3

Related Questions