简体   繁体   中英

How to customize a modelform widget in Django 1.1?

I'm trying to modify a Django form to use a textarea instead of a normal input for the "address" field in my house form. The docs seem to imply this changed from Django 1.1 (which I'm using) to 1.2. But neither approach is working for me. Here's what I've tried:

class HouseForm(forms.ModelForm):
    address = forms.Textarea() # Should work with django 1.1, but doesn't

    class Meta:
        model = House
        #widgets = { 'address': forms.Textarea() } # 1.2 style - doesn't work either.

I think Textarea needs to be assigned as a widget.

Try

class HouseForm(forms.ModelForm):
    address = forms.CharField(widget=forms.Textarea)

    class Meta:
        model = House

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM