Question

I am trying to use django-social-auth to implement google openid login into my app, my problem is that I get this error:

TemplateSyntaxError at /login
Caught ImportError while rendering: cannot import name get_backend
Request Method: GET
Request URL:    #############################
Django Version: 1.3.1
Exception Type: TemplateSyntaxError
Exception Value:    
Caught ImportError while rendering: cannot import name get_backend
Exception Location: /home/group018/web/WSProject/social_auth/views.py in <module>, line 19
Python Executable:  /usr/bin/python2.7
Python Version: 

At the exception location you can see the hierarchy of my project.

The view.py file is as follows:

from functools import wraps

from django.http import HttpResponseRedirect, HttpResponse,HttpResponseServerError
from django.core.urlresolvers import reverse
from django.contrib.auth import login, REDIRECT_FIELD_NAME
from django.contrib.auth.decorators import login_required
from django.contrib import messages
from django.utils.importlib import import_module
from django.views.decorators.csrf import csrf_exempt

from WSProject.social_auth.utils import sanitize_redirect, setting, log,backend_setting, clean_partial_pipeline
from WSProject.social_auth.backends import get_backend

DEFAULT_REDIRECT = setting('SOCIAL_AUTH_LOGIN_REDIRECT_URL') or setting('LOGIN_REDIRECT_URL')
LOGIN_ERROR_URL = setting('LOGIN_ERROR_URL', setting('LOGIN_URL'))
RAISE_EXCEPTIONS = setting('SOCIAL_AUTH_RAISE_EXCEPTIONS', setting('DEBUG'))
PROCESS_EXCEPTIONS = setting('SOCIAL_AUTH_PROCESS_EXCEPTIONS','social_auth.utils.log_exceptions_to_messages')


def dsa_view(redirect_name=None):

.
.
.

the function get_backend is defined in WSProject/social_auth/backends/__init__.py and I have tried to import it as:

from WSProject.social_auth.backends.__init__ import get_backend

But it doesn't work... any idea?

Note that the import below to the one I said is working

SOLVED: Finally I did it, the problem was the libraries, they were not correctly installed as jpic said.

Was it helpful?

Solution

Did you try this ?

from social_auth.backends import get_backend

You should not hardcode the name of your project in your code. That makes the code less portable.

If that doesn't work, then you haven't install django-social-auth correctly. Fix your setup:

  1. Create a virtualenv, in the parent directory of your project seems fair: virtualenv /path/to/venv

  2. Activate the virtualenv: source /path/to/venv/bin/activate

  3. Install an app ie. from git: pip install -e git+git://github.com/omab/django-social-auth.git#egg=social_auth

I also wrote a more detailed article on django, virtualenv and pip which should be of your interrest.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top