很简单。
这是我的个人资料模型:
class Profile(models.Model):
owner = models.OneToOneField(User)
slogan = models.TextField(null=True)
twitter = models.CharField(max_length = 100,null=True)
web_site = models.CharField(max_length=100,null=True)
email = models.CharField(max_length = 100,null=True)
def create_user(sender,instance,created,**kwargs):
if created:
Profile.objects.create(owner=instance)
post_save.connect(create_user, sender=User)
def __unicode__(self):
return self.email
和模型形式:
class profile_form(ModelForm):
slogan = forms.CharField(required=False,max_length=100,widget=forms.Textarea(attrs={'placeholder':'Site Sloganı','rows':'4',}))
#title = forms.CharField(required=False,max_length=20,widget=forms.TextInput(attrs={'placeholder': 'Site Başlığı',}))
email = forms.CharField(required=False,widget=forms.TextInput(attrs={'placeholder':'E-Mail Adresi',}))
twitter = forms.CharField(required=False,widget=forms.TextInput(attrs={'placeholder':'Twitter Adresi',}))
web_site = forms.CharField(required=False,widget=forms.TextInput(attrs={'placeholder':'Web Siteniz',})
class Meta:
model = Profile
当我尝试导入 blog.forms 时,它会在第 50 行抛出无效的语法错误,其中包括“class Meta”。
没有这样的。它刚刚显示。
谢谢你;