97👍
CharField
might be what you are looking for.
EDIT: To clarify, the docs mention TextField
as a model field type. You cannot use it as form field. The table that the OP pointed out indicates that a TextField
in a model is represented as a CharField
(with widget=forms.Textarea
) in a corresponding ModelForm. I would imagine, then, that there is no form field with Textarea
as its default widget.
If I were to guess why Django made this choice, I would say that having two fields that differ only in the widget they use, not in the type of data being stored, validation, etc. might be considered useless by the people at Django and hence you have to manually change the widget.
98👍
If you want a textarea you can use the forms.CharField with the forms.TextArea widget.
class ContactForm(forms.Form):
message = forms.CharField(widget=forms.Textarea)
- [Django]-How to define two fields "unique" as couple
- [Django]-Django template system, calling a function inside a model
- [Django]-A Better Django Admin ManyToMany Field Widget
3👍
Just want to add a better example for beginners like me, as all mentioned above, there is no TextFile for ModelForm, and if you need to use it, for the OP’s case, should be:
first_name = forms.CharField(
widget=forms.TextInput(attrs={'placeholder': 'first name'}),
label=_(u'First name'),
required=False)
And if you do need a textarea field for description or comment, then you can use Textarea widget:
description = forms.CharField(
widget=forms.Textarea(attrs={'placeholder': 'Please enter the description'}))
- [Django]-Django 2 – How to register a user using email confirmation and CBVs?
- [Django]-What's the point of Django's collectstatic?
- [Django]-How to read the database table name of a Model instance?
0👍
forms.TextField doesn’t exist, check out the documentation you refer to, it’s only for the models.
You can prove this to yourself by looking at the actual django source django/forms/fields.py.
You must use CharField with widget=forms.TextArea as you say in your comments.
- [Django]-Django: Example of generic relations using the contenttypes framework?
- [Django]-Accessing "Media" files in Django
- [Django]-How to create user from django shell
- [Django]-Django signals vs. overriding save method
- [Django]-Django: Reference to an outer query may only be used in a subquery
- [Django]-Django: How can I protect against concurrent modification of database entries