gpt4 book ai didi

python - django-social-auth 中的 Django 错误

转载 作者:太空狗 更新时间:2023-10-30 01:46:18 25 4
gpt4 key购买 nike

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

File "./manage.py", line 10, in <module>
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 <module>
from django.utils.importlib import import_module
ImportError: No module named importlib

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

最佳答案

似乎 django-social-auth 已经 issues使用django 1.8,所以我不怀疑django 1.9是否有问题。我会推荐使用 django-allauth因为它是最used/rated package用于社交网络,并且很容易配置:

  1. pip install django-allauth
  2. 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
  3. urls.py 添加:

    urlpatterns = patterns('',
    ...
    #Auth URLS
    url(r'^accounts/', include('allauth.urls')),
    )
  4. 最后应用数据库迁移

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

  6. 配置您的 Facebook 应用程序以获取 key ,然后在 http://127.0.0.1:8000/admin/socialaccount/socialapp 为 Facebook 创建一个社交应用程序

--> 你也可以找到这个 tutoriel有用的

关于python - django-social-auth 中的 Django 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34253642/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com