本示例是摘自Proto扩展Django用户配置文件的摘录
fromdjango.dbimport models from django.contrib.auth.models import User from django.db.models.signals import post_save class UserProfile(models.Model): user = models.OneToOneField(User, related_name='user') website = models.URLField(default='', blank=True) bio = models.TextField(default='', blank=True) def create_profile(sender, **kwargs): user = kwargs["instance"] if kwargs["created"]: user_profile = UserProfile(user=user) user_profile.save() post_save.connect(create_profile, sender=User)