如何在第一次登录facebook后存储用户名(在数据库中)?

2024-06-17 11:17:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在创建一个网站,可以选择使用facebook,google等登录(比如stackoverflow.com网站它可以选择以google用户的身份登录。在

我的问题是

  • 如何管理用户帐户(我是指用户活动)

我的用户数据库是

调节器/模型.py在

class Employer(models.Model):
    user=models.OneToOneField(User)
    companyname= models.CharField(max_length=100,blank=True)
    leader=models.BooleanField(default=True)
    #avatar = models.ImageField("Profile Pic", upload_to="images/", blank=True, null=True)    
    def __unicode__(self):
        return self.user.username


class Jobseeker(models.Model):
    user=models.OneToOneField(User)
    #avatar = models.ImageField("Profile Pic", upload_to="images/", blank=True, null=True)
    def __unicode__(self):
        return self.user.username

在fblogin.html在

^{pr2}$

我是否需要添加类似于in的内容

调节器/模型.py在

......other models(listed above)

class userFacebook(models.Model):
    user=models.OneToOneField(User)

并在第一次登录facebook后创建用户

在网址.py在

.....other urls

url(r'^createfbuser/$', 'create_facebook_user_ajax'),

调节器/视图.py在

def create_facebook_user_ajax(request):
    f_name=request.GET['param1']
    f_id=request.GET['param2']        
    User.objects.create_user(##########what are the things i want to provide here.)
    #if i provide the facebook username then there may be already a user with same username

或者有其他方法。。在

抱歉,我刚登录facebook。在


Tags: to用户pyselftruemodelfacebookmodels
1条回答
网友
1楼 · 发布于 2024-06-17 11:17:29

django-social-auth是一个非常容易安装的解决方案,可以满足您的需求。它们是其他django应用程序,您可以在hackerluddite's blog上了解它。在

引用github自述django social auth存储库

Django Social Auth

Django Social Auth is an easy way to setup social authentication/authorization mechanism for Django projects.

Crafted using base code from django-twitter-oauth and django-openid-auth, it implements a common interface to define new authentication providers from third parties.

别忘了启动github repo。在

相关问题 更多 >