我已经在我的工作应用程序中安装了 django-facebook,但它产生了很多问题。我在这里安装了 django-facebook ,但我无法正确实现它。
在 facebook/example 中,当我尝试连接到 facebook 时,它会提示用户输入 facebook 凭据,但由于出现以下错误,它无法重定向到下一页:
用户或个人资料没有属性 facebook_id
我确实 manage.py syncdb 但在 facebook/example 中连接到 facebook 后,facebook 属性在 DB 中保持为“空”。
我在文档中添加了以下代码:
帐户/模型.py
from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save
from django_facebook.models import FacebookProfileModel
class User_info(FacebookProfileModel):
user_id = models.ForeignKey(User)
dob = models.DateField(blank=True, null=True)
contact = models.IntegerField(max_length=20, blank=True, null=True)
avatar = models.ImageField(upload_to='user_images', default='user_images/root.jpeg', null=True, blank=True)
def create_facebook_profile(sender, instance, created, **kwargs):
if created:
User_info.objects.create(user_id=instance)
post_save.connect(create_facebook_profile, sender=User)
设置.py
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.admindocs',
'account',
'django_facebook',
)
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_facebook.context_processors.facebook',
)
AUTHENTICATION_BACKENDS = (
'django_facebook.auth_backends.FacebookBackend',
'django.contrib.auth.backends.ModelBackend',)
FACEBOOK_APP_ID = 'xxxxxxxxxxxxx'
FACEBOOK_APP_SECRET = 'xxxxxxxxxxxxxx'
网址.py
urlpatterns = patterns('',
url(r'^accounts/login/$', login, {'template_name': 'login.html'}),
url(r'^accounts/logout/$', logout, {'next_page': '/accounts/login/'}, name='auth_logout',),
url(r'^accounts/signup/$', account.views.register, name='signup'),
url(r'^facebook/', include('django_facebook.urls')),
)
请帮助我。谢谢。