我安裝了social-auth-app-django
,並按照指南here將Facebook登錄集成到django 1.8.18。問題是當我去「http://localhost:8000/social-auth/login/facebook/」我得到以下錯誤如何解決Facebook上的django社交認證錯誤?
無法加載URL:此URL的域未包含在應用程序的域中。 要加載此網址,請將您的 應用的所有網域和子網域添加到應用設置中的應用域名字段。
這裏是我的settings.py文件
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
print (BASE_DIR)
SECRET_KEY = 'x220#z=kwd)kjiu#u+p$)v0lu+rspyosg+)l*k$ux9j)1h'
DEBUG = True
ALLOWED_HOSTS = ['localhost']
INSTALLED_APPS = (
...
'account',
'social_django', #social classes
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
'social_django.middleware.SocialAuthExceptionMiddleware',
)
ROOT_URLCONF = 'bookmark.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'social_django.context_processors.backends', # <--
'social_django.context_processors.login_redirect', # <--
],
},
},
]
WSGI_APPLICATION = 'bookmark.wsgi.application'
STATIC_URL = '/static/'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR,'media/')
from django.core.urlresolvers import reverse_lazy
LOGIN_REDIRECT_URL = reverse_lazy('dashboard')
LOGIN_URL = reverse_lazy('login')
LOGOUT_URL = reverse_lazy('logout')
AUTHENTICATION_BACKENDS = (
'social_core.backends.facebook.FacebookOAuth2', #< --facebook
'django.contrib.auth.backends.ModelBackend',
'account.authentication.EmailAuthBackend',
)
SOCIAL_AUTH_FACEBOOK_KEY='1742581762468139'
SOCIAL_AUTH_FACEBOOK_SECRET='eae7dsfdsfdsf90b219becb84'
urls.py文件
from django.conf.urls import include, url
from django.contrib import admin
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^social-auth/',include('social_django.urls', namespace='social')), # <-- social facebook
url(r'^account/',include('account.urls')),
url(r'^$','account.views.dashboard',name="dashboard"),
]
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_ROOT,
document_root=settings.MEDIA_ROOT)
我也改變了本地主機像「bookmarks.com」,並在/ etc/hosts文件中更改它,但得到了山姆e error
它對我有效..感謝 – Romeo