使用django-social-auth进行ImportError

时间:2012-03-05 09:59:03

标签: python django django-socialauth

我正在尝试使用django-social-auth将google openid登录到我的应用中,我的问题是我收到此错误:

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: 

在异常位置,您可以看到我的项目的层次结构。

view.py文件如下:

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

.
.
.

函数get_backend在WSProject/social_auth/backends/__init__.py中定义,我试图将其导入为:

from WSProject.social_auth.backends.__init__ import get_backend

但它不起作用......任何想法?

请注意,下面的导入到我说的那个正在工作

解决:最后我做了,问题是库,他们没有正确安装,因为jpic说。

1 个答案:

答案 0 :(得分:2)

你试过这个吗?

from social_auth.backends import get_backend

您不应该在代码中对项目名称进行硬编码。这使得代码不那么便携。

如果这不起作用,那么您还没有正确安装django-social-auth。修复您的设置:

  1. 在项目的父目录中创建virtualenv 似乎公平:virtualenv /path/to/venv

  2. 激活virtualenv source /path/to/venv/bin/activate

  3. 安装应用即。来自git:pip install -e git+git://github.com/omab/django-social-auth.git#egg=social_auth

  4. 我还写了一篇关于django, virtualenv and pip的更详细的文章,这篇文章应该是你的骚动。

相关问题