gpt4 book ai didi

python - 无法在 Django 站点上配置 Facebook 登录

转载 作者:太空宇宙 更新时间:2023-11-03 11:04:38 25 4
gpt4 key购买 nike

我有一个由 Heroku 托管的个人 Django 网站,我正在尝试配置 Facebook 登录。我正在使用 django-socialregistration这看起来很简单。无论我是在本地还是在生产环境中查看我的站点,我都会不断收到错误消息:

应用程序配置不允许给定的 URL。应用程序的设置不允许一个或多个给定的 URL。它必须与网站 URL 或 Canvas URL 匹配,或者域必须是应用域之一的子域。

我希望在本地出现该错误,没关系。我已经阅读了关于该主题的所有其他答案,所有答案似乎都表明问题出在“基本”选项卡上的“站点 URL”设置中。我试过:

  • sitename.com
  • www.sitename.com
  • http://www.sitename.com
  • https://www.sitename.com
  • 网站名称.herokuapp.com

没有任何区别。我错过了什么?

编辑

网址.py

urlpatterns = patterns('',
url(r'^$', 'mainsite.views.base', name='base'),
url(r'^quiz/$', 'quiz.views.quiz', name='quiz'),
url(r'^results/$', 'quiz.views.results', name='results'),
url(r'^wedding_party/$', 'mainsite.views.wedding_party',
name='wedding_party'),
url(r'^location/$', 'mainsite.views.location', name='location'),
url(r'^story/$', 'mainsite.views.story', name='story'),
url(r'^high_scores/$', 'quiz.views.high_scores', name='high_scores'),
url(r'^photos/$', 'photoalbum.views.photo_album', name='photo_album'),
url(r'^guestbook/$', 'mainsite.views.guestbook', name='guestbook'),
url(r'^map/$', 'mainsite.views.map', name='map'),
url(r'^afterparty/$', 'mainsite.views.afterparty', name='afterparty'),
url(r'^lodging/$', 'mainsite.views.lodging', name='lodging'),
url(r'^social/', include('socialregistration.urls',
namespace='socialregistration')),
url(r'^admin/', include(admin.site.urls)),
)

Facebook 设置(我尝试过的众多配置之一):

基本 > 网站 > 网站 URL:http://www.sitename.com/
高级 > 有效的 OAuth 重定向 URI:http://www.sitename.com/ (不知道这个设置是做什么的)

编辑:

( Canvas 设置是新的,但没有帮助) enter image description here enter image description here enter image description here

设置.py

try:
from config import SECRET_KEY, FACEBOOK_SECRET_KEY, FACEBOOK_APP_ID
DEBUG = True
except ImportError:
DEBUG = False
SECRET_KEY = os.environ['SECRET_KEY']
FACEBOOK_APP_ID = os.environ['FACEBOOK_APP_ID']
FACEBOOK_SECRET_KEY = os.environ['FACEBOOK_SECRET_KEY']

# Django settings for wedding project.

TEMPLATE_DEBUG = DEBUG

ADMINS = (
('xxxx', 'xxxxx@gmail.com'),
)

MANAGERS = ADMINS

DATABASES = {
'default': {
# Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
# 'ENGINE': 'django.db.backends.postgresql_psycopg2',
# 'NAME': 'django_app_1',
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'wedding.db',
# The rest is not used with sqlite3:
# 'USER': 'xxxx',
# 'PASSWORD': 'xxxx',
# 'HOST': 'localhost',
# 'PORT': '5432',

}
}
# Hosts/domain names that are valid for this site; required if DEBUG is False
# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
ALLOWED_HOSTS = ['*']

# Parse database configuration from $DATABASE_URL
if not DEBUG:
import dj_database_url
DATABASES['default'] = dj_database_url.config()

SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# In a Windows environment this must be set to your system time zone.
TIME_ZONE = 'America/New_York'

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'

SITE_ID = 1

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True

# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale.
USE_L10N = True

# If you set this to False, Django will not use timezone-aware datetimes.
USE_TZ = True

# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/var/www/example.com/media/"
MEDIA_ROOT = \
'/Users/xxxxx/code/wedding/mainsite/static/images/photoalbum/'

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://example.com/media/", "http://media.example.com/"
MEDIA_URL = 'http://127.0.0.1:8000/photos/'

import os
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = 'mainsite/static/'
STATIC_URL = '/static/'

STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'staticfiles'),
)

# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)

# Make this unique, and don't share it with anybody.

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)

MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django_user_agents.middleware.UserAgentMiddleware',
)

ROOT_URLCONF = 'wedding.urls'

# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'wedding.wsgi.application'

TEMPLATE_DIRS = (
'mainsite/templates',
'quiz/templates',
'photoalbum/templates',
)

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
'django.contrib.admindocs',
'mainsite',
'quiz',
'photoalbum',
'django_google_maps',
'django_user_agents',
'south',
'socialregistration',
'socialregistration.contrib.facebook'
)

# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error when DEBUG=False.
# See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'handlers': {
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
}
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
}
}

TEMPLATE_CONTEXT_PROCESSORS = (
'django.contrib.auth.context_processors.auth',
'django.core.context_processors.debug',
'django.core.context_processors.i18n',
'django.core.context_processors.media',
'django.core.context_processors.static',
'django.core.context_processors.tz',
'django.core.context_processors.request',
'django.contrib.messages.context_processors.messages',
)

AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'socialregistration.contrib.facebook.auth.FacebookAuth',
)

编辑(站点模块)如评论中所述,Facebook 按钮导致 redirect_uri=http%3A%2F%2Fexample.com%2Fsocial%2Ffacebook%2Fcallback%2F&client_i‌ d=582393191868558。

example.com 来自站点模块;我删除了它并用正确的站点域替换了它。链接现在转到:redirect_uri=http%3A%2F%2Fwienerwedding.com%2Fsocial%2Ffacebook%2Fcallback%2F&client_i‌ d=582393191868558 但它仍然不起作用。 (同样的错误)

最佳答案

请向我们展示您的 Facebook 应用配置,我认为这是您未填写的 App Domains

您需要创建一个facebook 应用,使用+ 添加平台

试试这些设置:

Basic >

-App Domains : sitename.com

-App on Facebook :

--Canvas URL : http://sitename.com/

--Secure Canvas URL : https://sitename.com/

Advanced >

-Valid OAuth redirect URIs : http://sitename.com/

关于python - 无法在 Django 站点上配置 Facebook 登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23507249/

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