当前位置:  开发笔记 > 编程语言 > 正文

Django在django-social-auth中出错

如何解决《Django在django-social-auth中出错》经验,为你挑选了2个好方法。

我是Django的新手.我正在我的应用程序中实现facebook身份验证.我在终端输出中得到的错误是这样的;

File "./manage.py", line 10, in 
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 350, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 324, in execute
    django.setup()
  File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "/usr/local/lib/python2.7/dist-packages/django/apps/config.py", line 202, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/usr/local/lib/python2.7/dist-packages/social_auth/models.py", line 4, in 
    from django.utils.importlib import import_module
ImportError: No module named importlib 

我做错了什么?我新安装的django-python-social是否正确安装?



1> DhiaTN..:

似乎django-social-auth已经与django 1.8 有问题,所以我不知道它是否与django 1.9有问题.我建议使用django-allauth,因为它是社交网络中使用最多/额定的包,并且它易于配置:

    pip install django-allauth

    settings.py配置

    TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, "templates")],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                ....
                "django.core.context_processors.request",
                # allauth specific context processors
                "allauth.account.context_processors.account",
                "allauth.socialaccount.context_processors.socialaccount",
            ],
        },
    },]
    
    AUTHENTICATION_BACKENDS = (
        # Default backend 
        "django.contrib.auth.backends.ModelBackend",
        # `allauth` specific authentication methods, such as login by e-mail
        "allauth.account.auth_backends.AuthenticationBackend",
    )
    
    INSTALLED_APPS += (
        # The Django sites framework is required
        'django.contrib.sites',
        'allauth',
        'allauth.account',
        'allauth.socialaccount',
         # Login Facebook provider
         'allauth.socialaccount.providers.facebook',
    )
    SITE_ID = 1
    

    urls.py中 添加:

    urlpatterns = patterns('',
        ...
        #Auth URLS
        url(r'^accounts/', include('allauth.urls')),
    )
    

    最后应用数据库迁移

    运行服务器并转到http://127.0.0.1:8000/admin/sites/site的管理界面, 并为localhost,127.0.0.1:8000或您的网站域创建一个站点进行生产.它的id应等于设置之前配置的SITE_ID.

    配置您的Facebook应用程序以获取密钥,然后在http://127.0.0.1:8000/admin/socialaccount/socialapp创建Facebook社交应用程序

- >你也可能觉得这个tutoriel很有用



2> utkbansal..:

django-social-auth已被正式弃用,转而使用python-social-auth.所以你不应该使用它.此外,导入错误很可能是由于与Django 1.9不兼容,因为django已经弃用了importlib.


不.请改用python-social-auth
推荐阅读
勤奋的瞌睡猪_715
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有