如何在django中显示文本框

时间:2014-04-10 11:37:07

标签: python django

Models.py

class AllUsers(models.Model):
    user_fullname = models.CharField(max_length=200)
    user_email = models.EmailField()
    dob = models.DateField()
    user_cv = models.FileField(upload_to = get_upload_file_name)
    user_department_id = models.ForeignKey(Department)
    user_FK = models.ForeignKey(User)
    coverletter = models.TextField() //THIS IS TEXT AREA

Forms.py:

class AllUsersForm(forms.ModelForm):
    dob= forms.DateField(widget=DateInput()) 
    class Meta:
        model = AllUsers

        fields = ('user_fullname','user_email','dob','user_cv','user_department_id',
                  'coverletter')

问题: enter image description here

coverletter有文字字段,但输入任何文字都很小。为什么呢?

3 个答案:

答案 0 :(得分:2)

尝试这样的事情

coverletter = forms.CharField(required=False,       widget=forms.Textarea(attrs={'rows': 4, 'cols': 40})) //rows and colums of the textarea

答案 1 :(得分:1)

您应该为此字段指定小部件。它可以在模型中完成:

coverletter = models.TextField(widget=forms.Textarea)

答案 2 :(得分:1)

这是一个类似于我在forms.py中对textarea的例子。也许它也适用于你。

class AllUsersForm(forms.ModelForm):
    dob= forms.DateField(widget=DateInput()) 
    class Meta:
        model = AllUsers

        fields = ('user_fullname','user_email','dob','user_cv','user_department_id',
                  'coverletter')

        widgets = {
            'coverletter': Textarea(attrs={'class': '???', 'rows': 5}),
        }

我相信"行:"声明可能会让textarea对您更加明显。