问题
I am newbie in Django. I am implementing the facebook authentication in my app. The Error that i am getting in my terminal output is like ;
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
What i am doing wrong? IS my newly installed django-python-social installed correctly?
回答1:
It seems like django-social-auth have already issues with django 1.8, so I don't wonder if it has problems with django 1.9. I will recommand to use django-allauth since it's the most used/rated package for social network, and it's easy to configure:
pip install django-allauthsettings.py config
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 = 1in urls.py add:
urlpatterns = patterns('', ... #Auth URLS url(r'^accounts/', include('allauth.urls')), )Finally apply database migration
run server and go to the admin interface at http://127.0.0.1:8000/admin/sites/site and create a Site for the localhost, 127.0.0.1:8000, or your website domain for production. It should have an id equal to the SITE_ID configured before in the setting.
Configure your facebook app to get secret key, and then create a Social Application for Facebook at http://127.0.0.1:8000/admin/socialaccount/socialapp
--> you may also find this tutoriel useful
回答2:
django-social-auth has officially been deprecated in favour of python-social-auth. So you should not be using it. Moreover the import error is most probably due to incompatibility with Django 1.9 as importlib has been deprecated from django.
来源:https://stackoverflow.com/questions/34253642/django-error-in-django-social-auth