Django REST框架和python-social-auth用于注册/登录用户。

10

我需要为移动应用程序实现一些REST API。

我想使用Django REST框架。

用户(移动端)只能使用Facebook注册帐户,我想使用python-social-auth进行此注册/登录。

由于我是新手,所以看了很多有关此的教程/文档/示例。

我只找到了一个关于Django + python_social_auth的完整教程,但我想确切地知道使用REST-api进行用户注册/登录的最佳实践。

哪里可以找到一个完整的示例?

在我的简单测试中,我也遇到了问题: 当我尝试使用这个示例时:

@psa('social:complete')
def register_by_access_token(request, backend):
    # This view expects an access_token GET parameter, if it's needed,
    # request.backend and request.strategy will be loaded with the current
    # backend and strategy.
    token = request.GET.get('access_token')
    user = request.backend.do_auth(request.GET.get('access_token'))
    if user:
        login(request, user)
        return 'OK'
    else:
        return 'ERROR'

我遇到了这个错误:

u'social' 不是一个已注册的命名空间

我也尝试在我的设置中添加 SOCIAL_AUTH_URL_NAMESPACE = 'myApp',但它并没有解决问题。

2个回答

7

感谢您的请求!Django-all-auth集成到Django-rest-auth中了吗?只需按照以下链接中的说明安装和配置两者即可:http://django-rest-auth.readthedocs.org/en/latest/installation.html - Safari
2
您需要单独安装django-restframework和django-allauth,然后可以按照链接中的说明进行操作。如果你想看一下如何在前端集成,请确保查看他们的angular app https://github.com/Tivix/angular-django-registration-auth - xxx

4

我知道用户已经选择了一个答案,但是由于那个答案指向了另一个库,所以在这里提供我的答案,以防后来有人需要:

"social"是你必须给python-social-auth提供的url命名空间。你必须在你项目的urls.py的urlpatterns列表中包含以下行:

urlpatterns = [
    url(r'^social/', include('social.apps.django_app.urls', namespace="social")
    # All other remaining urls here.
]

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接