如何使用django注册创建用户配置文件?

如何使用django注册创建用户配置文件?,django,model,profile,django-registration,Django,Model,Profile,Django Registration,在django 1.7中,我使用来处理用户注册,并且我想为每个新注册的用户自动创建一个UserProfile实例 因此,在模型中,我有: class UserProfile(models.Model): username = models.OneToOneField(User) name = models.CharField(max_length=30) occupation = models.CharField(max_length=50) city = mod

在django 1.7中,我使用来处理用户注册,并且我想为每个新注册的用户自动创建一个UserProfile实例

因此,在模型中,我有:

class UserProfile(models.Model):
    username = models.OneToOneField(User)
    name = models.CharField(max_length=30)
    occupation = models.CharField(max_length=50)
    city = models.CharField(max_length=30)


    @models.permalink
    def get_absolute_url(self):
        return ('view_pirate', None, {'username': self.account.user})    

    def __unicode__(self):
        return unicode(self.username) 

#**this line is supposed to create user profile****    
User.profile = property(lambda u:UserProfile.objects.get_or_create(username=u)[0])  
但是,当我检查数据库时,在新用户注册后,不会在userprofile\u userprofile中创建新行。这里怎么了?
如果该行位于错误的位置,它应该在哪里?

您在哪里编写了最后一行,应该创建用户?就在上面所示的类的下面。您应该将它放在视图中,您正在处理注册部分..wonder。。再来。。告诉你如何创建用户?@vijayshanker我遵循了本教程,其中建议该行应位于model.py中: