无法在django网站上配置facebook登录

时间:2014-05-07 01:33:02

标签: python django facebook heroku

我有一个由Heroku主持的个人Django网站,我正在尝试配置Facebook登录。我正在使用django-socialregistration这看起来非常简单。无论我是在本地查看我的网站还是在制作中,我都会收到错误:

Given URL is not allowed by the Application configuration.: One or more of the given URLs is not allowed by the App's settings. It must match the Website URL or Canvas URL, or the domain must be a subdomain of one of the App's domains.

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

  • sitename.com
  • www.sitename.com
  • http://www.sitename.com
  • https://www.sitename.com
  • sitename.herokuapp.com

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

修改

urls.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设置(我尝试过的众多配置之一):

基本>网站>网站网址:http://www.sitename.com/
高级>有效的OAuth重定向URI:http://www.sitename.com/(不确定此设置的用途)

编辑:

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

settings.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来自Sites模块;我删除了它并用正确的站点域替换它。链接现在转到:redirect_uri = http%3A%2F%2Fwienerwedding.com%2Fsocial%2Ffacebook%2Fcallback%2F& client_i d = 582393191868558但它仍然无效。 (同样的错误)

2 个答案:

答案 0 :(得分:2)

请告诉我们您的Facebook应用配置,我认为这是您错过的App Domains

您需要创建 Facebook应用,使用 +添加平台

尝试以下设置:

  

基本>

     

-App域名:sitename.com

     

-App on Facebook:

     

- 画布网址:http://sitename.com/

     

- 安全画布网址:https://sitename.com/

     

高级>

     

-Valid OAuth重定向URI:http://sitename.com/

答案 1 :(得分:1)

如果我们无法看到您在fb应用中的设置,则很难说出任何内容。

试试这个:

Settings -> Basic -> Website platform -> Site URL: http://www.sitename.com/
Settings -> Advanced -> Security -> Valid OAuth redirect URIs: http://www.sitename.com/facebook/callback