python - 使用 django-social-auth 出现导入错误

标签 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 所说的那样正确安装。

最佳答案

你尝试过这个吗?

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

我还在 django, virtualenv and pip 上写了一篇更详细的文章这应该是您感兴趣的。

关于python - 使用 django-social-auth 出现导入错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9564685/

相关文章:

python - django-social-auth 使用 Google OpenID 给出 502 错误,但只有少数用户

django - 不是 JSON 可序列化 - django 社交身份验证 Facebook 登录

Python Bottle SSE

python - 在 Python3 中,当我读取二进制文件时,为什么 'b' 会添加到我的内容前面?

python - 从 STEP 文件解析 BReps

django - 如何查询多对多字段中仅描述的对象存在的位置

python - 如何完成 django-userena 和 Social Auth 的集成

C# 等效于 Python 的 urlsafe_b64encode

python - 如何在 Django 中处理 PUT 请求? (不在drf中)

python - 如何使用 python 和 openssl 验证 webhook 签名