2012-01-17 90 views
0

我使用django socialauth of OMABI am using the example作品旁边的文件并没有改变什么,但我把它放在local_settings.py:叽叽喳喳不工作在Django socialauth

TWITTER_CONSUMER_KEY    = 'Mk' this is no real 
TWITTER_CONSUMER_SECRET   = 'MTw' this is no real 
FACEBOOK_APP_ID     = '' 
FACEBOOK_API_SECRET    = '' 
LINKEDIN_CONSUMER_KEY    = '' 
LINKEDIN_CONSUMER_SECRET   = '' 
ORKUT_CONSUMER_KEY    = '' 
ORKUT_CONSUMER_SECRET    = '' 
GOOGLE_OAUTH2_CLIENT_ID   = '' 
GOOGLE_OAUTH2_CLIENT_SECRET  = '' 
SOCIAL_AUTH_CREATE_USERS   = True 
SOCIAL_AUTH_FORCE_RANDOM_USERNAME = False 
SOCIAL_AUTH_DEFAULT_USERNAME  = 'socialauth_user' 
SOCIAL_AUTH_COMPLETE_URL_NAME  = 'socialauth_complete' 
LOGIN_ERROR_URL     = '/login/error/' 
#SOCIAL_AUTH_USER_MODEL   = 'app.CustomUser' 
SOCIAL_AUTH_ERROR_KEY    = 'socialauth_error' 
GITHUB_APP_ID      = '' 
GITHUB_API_SECRET     = '' 
FOURSQUARE_CONSUMER_KEY   = '' 
FOURSQUARE_CONSUMER_SECRET  = '' 

这是我的settings.py

from os.path import abspath, dirname, basename, join 

try: 
    import social_auth 
except ImportError: 
    import sys 
    sys.path.insert(0, "..") 

DEBUG = True 
TEMPLATE_DEBUG = DEBUG 

ROOT_PATH = abspath(dirname(__file__)) 
PROJECT_NAME = basename(ROOT_PATH) 

ADMINS = (
    # ('Your Name', '[email protected]'), 
) 
MANAGERS = ADMINS 

DATABASES = { 
    'default': { 
     'ENGINE': 'django.db.backends.sqlite3', 
     'NAME': 'test.db', 
    } 
} 

TIME_ZONE = 'America/Chicago' 
LANGUAGE_CODE = 'en-us' 
SITE_ID = 1 

USE_I18N = True 
USE_L10N = True 

MEDIA_ROOT = '' 
ADMIN_MEDIA_PREFIX = '/admin-media/' 
MEDIA_URL = '' 

SECRET_KEY = 't2eo^kd%k+-##[email protected]_x__$j0(ps4p0q6eg*c4ttp9d2n(t!iol' 

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', 
) 

ROOT_URLCONF = 'example.urls' 

TEMPLATE_DIRS = (
    join(ROOT_PATH, 'templates') 
) 

INSTALLED_APPS = (
    'django.contrib.auth', 
    'django.contrib.contenttypes', 
    'django.contrib.sessions', 
    'django.contrib.sites', 
    'django.contrib.messages', 
    'django.contrib.admin', 
    'social_auth', 
    'app', 
) 
SOCIAL_AUTH_ENABLED_BACKENDS = ('google', 'google-oauth', 'facebook', 'twitter') 

AUTHENTICATION_BACKENDS = (
    'social_auth.backends.twitter.TwitterBackend', 
    'social_auth.backends.facebook.FacebookBackend', 
    'social_auth.backends.google.GoogleOAuthBackend', 
    'social_auth.backends.google.GoogleOAuth2Backend', 
    'social_auth.backends.google.GoogleBackend', 
    'social_auth.backends.yahoo.YahooBackend', 
    'social_auth.backends.contrib.linkedin.LinkedinBackend', 
    'social_auth.backends.contrib.flickr.FlickrBackend', 
    'social_auth.backends.OpenIDBackend', 
    'social_auth.backends.contrib.livejournal.LiveJournalBackend', 
    'django.contrib.auth.backends.ModelBackend', 
) 


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.contrib.messages.context_processors.messages', 
    'social_auth.context_processors.social_auth_by_type_backends', 
) 

LOGIN_REDIRECT_URL = '/' 

try: 
    from local_settings import * 
except: 
    pass 

我有同样的problem as the user尝试重命名local_settings.py到local_settings_template.py并不起作用,反之亦然。这个用户不知道如何解决这个问题,不知道如何与你联系问。如果有人可以测试样品,看看是否有同样的问题会帮助我很多。

+0

发布您的settings.py – DTing 2012-01-17 17:21:58

+0

我修改了我的问题,并记住我正在使用示例 – oscar 2012-01-17 21:46:02

+0

请勿尝试启用您未使用的social_auth后端。 – DTing 2012-01-17 22:32:06

回答

0

我能得到的Twitter进行了以下修改工作

settings.py:

AUTHENTICATION_BACKENDS = (
    'social_auth.backends.google.TwitterBackend', 
) 

SOCIAL_AUTH_ENABLED_BACKENDS = ('twitter',) 

TWITTER_CONSUMER_KEY    = 'xxx' 
TWITTER_CONSUMER_SECRET   = 'yyy' 

INSTALLED_APPS = (
    'django.contrib.auth', 
    'django.contrib.contenttypes', 
    'django.contrib.sessions', 
    'django.contrib.sites', 
    'django.contrib.messages', 
    'django.contrib.staticfiles', 
    'social_auth', 
) 

urls.py:

url(r'', include('social_auth.urls')), 

当然这是需要:

% python manage.py syncdb 

要直接使用Twitter进行测试(无需配置任何其他项目/应用程序),只需浏览到/ login/twitter,然后您应该通过认证舞蹈,您的用户将被添加到数据库中,并且您将被重定向(到一个不存在的网址,但你会有用户信息)。

从那里你应该能够得到它与你的系统的工作。

+0

谢谢,我会尝试 – oscar 2012-01-19 04:12:56

+0

您在本地主机上工作的另一个问题?或者在您的Twitter应用程序中注册的主机上 – oscar 2012-01-19 04:26:29