Python 清洁的形式不';行不通
我正在尝试将我的用户用户名设置为小写。但不知怎么的,它不起作用。我只是看不出有错。。。为什么它不起作用 型号:Python 清洁的形式不';行不通,python,django,Python,Django,我正在尝试将我的用户用户名设置为小写。但不知怎么的,它不起作用。我只是看不出有错。。。为什么它不起作用 型号: class UserProfile(models.Model): # This line is required. Links UserProfile to a User model instance. user = models.OneToOneField(User) # The additional attributes we wish to includ
class UserProfile(models.Model):
# This line is required. Links UserProfile to a User model instance.
user = models.OneToOneField(User)
# The additional attributes we wish to include.
website = models.URLField()
# Override the __unicode__() method to return out something meaningful!
def __unicode__(self):
return self.user.username
表格:
您确定这指向的是
用户
模型,而不是用户配置文件
?请使用使用表单的代码更新您的问题,例如视图。为什么显示用户配置文件的代码?这似乎与表单没有任何关系,表单基于用户,不使用UserProfile中的任何字段。
class UserForm(forms.ModelForm):
password = forms.CharField(widget=forms.PasswordInput())
class Meta:
model = User
fields = ('username', 'email', 'password')
def clean_username(self):
username = self.cleaned_data['username'].lower()
return username