2012-05-15 34 views
1

我按照说明将Django-facebook安装到我的网站上,以允许用户在我的网站上注册,登录,邀请朋友和分享内容。我可以使用他们的Facebook帐户轻松地将用户注册到我的网站。但是,我很困惑如何注销它们,检索用户的Facebook用户名,以及如何集成mutliselect朋友邀请函。在django-facebook上检索用户名和邀请朋友

这里是MYS settings.py文件

TEMPLATE_CONTEXT_PROCESSORS = (
'django_facebook.context_processors.facebook', 
'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.contrib.messages.context_processors.messages', 
) 

AUTHENTICATION_BACKENDS = (
'django_facebook.auth_backends.FacebookBackend', 
'django.contrib.auth.backends.ModelBackend', 
) 

AUTH_PROFILE_MODULE = "appname.UserProfile" 

FACEBOOK_APP_ID = "<myappID>" 
FACEBOOK_APP_SECRET ="<myappsecretkey>" 

在我的models.py,我创建了一个自定义用户的个人资料如下:

# User model 
class UserProfile(FacebookProfileModel): 
user = models.OneToOneField(User) 
last_login = models.DateTimeField(blank=True, null=True) 
is_active = models.BooleanField(default=False) 
playedHours = models.FloatField(default = 0) 



playedSongs = models.ManyToManyField(Song, blank=True, null = True) 
invitedFriends = models.ManyToManyField('self', blank = True, null = True) 

def __unicode__(self): 
    return self.facebook_name 



from django.db.models.signals import post_save 
from django.dispatch import receiver 

@receiver(post_save, sender=User) 
def create_profile(sender, instance, created, **kwargs): 
    """Create a matching profile whenever a user object is created.""" 
    if created: 
    profile, new = UserProfile.objects.get_or_create(user=instance) 

在我加入这两条线的urls.py我不知道他们在做什么tbh:

(r'^facebook/', include('django_facebook.urls')), 
(r'^accounts/', include('django_facebook.auth_urls')), 

我想要实现的就是一旦用户使用faceboo注册k,我想获取他们的名字和个人资料图片,并允许他们邀请他们的朋友。

我一直在寻找(最新)的教程,我惨败于此。 任何帮助非常感谢! 谢谢

回答

0

要注销它们,auth_logout“/ logout /”url可能会有所帮助。

关于Facebook_name,看看FacebookProfileModel: facebook_name = models.CharField(MAX_LENGTH = 255,空=真)

所以,你可以通过profile_object.facebook_name访问它。