[英]Django Crispy Forms: Set rows for Text Area
When creating a Form with FormHelper()
, the text areas of my form (for TextField
s) are too big: They are set to 10 rows.使用FormHelper()
创建表单时,我的表单的文本区域(对于TextField
s)太大:它们设置为 10 行。 I'd like to set the number of rows.我想设置行数。 How can I do that?我怎样才能做到这一点?
My code:我的代码:
models.py
: models.py
:from django.db import models
class Spam(models.Model).
ham = models.CharField(max_length=10, blank=True, null=False, default='Some ham')
eggs = models.TextField(blank=True, null=False, default='', verbose_name="Lots of eggs")
forms.py
: forms.py
:from django import forms
from crispy_forms.helper import FormHelper
from crispyy_forms.layout import (Layout, Row, Column)
from .models import Spam
class SpamForm(forms.ModelForm):
class Meta():
model = Spam
fields = ('ham', 'eggs')
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_method = 'POST'
self.helper.layout = Layout(
Row(Column('ham', css_class='form-group col-12')),
Row(Column('eggs', css_class='form-group col-12')),
# HERE: How can I set the rows for the text area widget?
)
<!-- (ommited for brevity) -->
<div class="form-row " >
<div class="form_group col-12" rows="2">
<div id="div_id_eggs" class="form-group">
<label for="eggs" class="">Lots of eggs</label>
<div class="">
<textarea name="eggs" cols="40" rows="10" class="textarea form-control" id="eggs"></textarea>
<!-- ^^^^^^^^
<!-- THIS is what I'd like to change to "2" -->
</div>
</div>
</div>
</div>
<!-- (ommited for brevity) -->
When creating a Form with FormHelper()
, the text areas of my form (for TextField
s) are too big: They are set to 10 rows.使用FormHelper()
创建Form时,表单的文本区域(对于TextField
)太大:它们设置为10行。 I'd like to set the number of rows.我想设置行数。 How can I do that?我怎样才能做到这一点?
My code:我的代码:
models.py
: models.py
:from django.db import models
class Spam(models.Model).
ham = models.CharField(max_length=10, blank=True, null=False, default='Some ham')
eggs = models.TextField(blank=True, null=False, default='', verbose_name="Lots of eggs")
forms.py
: forms.py
:from django import forms
from crispy_forms.helper import FormHelper
from crispyy_forms.layout import (Layout, Row, Column)
from .models import Spam
class SpamForm(forms.ModelForm):
class Meta():
model = Spam
fields = ('ham', 'eggs')
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_method = 'POST'
self.helper.layout = Layout(
Row(Column('ham', css_class='form-group col-12')),
Row(Column('eggs', css_class='form-group col-12')),
# HERE: How can I set the rows for the text area widget?
)
<!-- (ommited for brevity) -->
<div class="form-row " >
<div class="form_group col-12" rows="2">
<div id="div_id_eggs" class="form-group">
<label for="eggs" class="">Lots of eggs</label>
<div class="">
<textarea name="eggs" cols="40" rows="10" class="textarea form-control" id="eggs"></textarea>
<!-- ^^^^^^^^
<!-- THIS is what I'd like to change to "2" -->
</div>
</div>
</div>
</div>
<!-- (ommited for brevity) -->
When creating a Form with FormHelper()
, the text areas of my form (for TextField
s) are too big: They are set to 10 rows.使用FormHelper()
创建Form时,表单的文本区域(对于TextField
)太大:它们设置为10行。 I'd like to set the number of rows.我想设置行数。 How can I do that?我怎样才能做到这一点?
My code:我的代码:
models.py
: models.py
:from django.db import models
class Spam(models.Model).
ham = models.CharField(max_length=10, blank=True, null=False, default='Some ham')
eggs = models.TextField(blank=True, null=False, default='', verbose_name="Lots of eggs")
forms.py
: forms.py
:from django import forms
from crispy_forms.helper import FormHelper
from crispyy_forms.layout import (Layout, Row, Column)
from .models import Spam
class SpamForm(forms.ModelForm):
class Meta():
model = Spam
fields = ('ham', 'eggs')
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_method = 'POST'
self.helper.layout = Layout(
Row(Column('ham', css_class='form-group col-12')),
Row(Column('eggs', css_class='form-group col-12')),
# HERE: How can I set the rows for the text area widget?
)
<!-- (ommited for brevity) -->
<div class="form-row " >
<div class="form_group col-12" rows="2">
<div id="div_id_eggs" class="form-group">
<label for="eggs" class="">Lots of eggs</label>
<div class="">
<textarea name="eggs" cols="40" rows="10" class="textarea form-control" id="eggs"></textarea>
<!-- ^^^^^^^^
<!-- THIS is what I'd like to change to "2" -->
</div>
</div>
</div>
</div>
<!-- (ommited for brevity) -->
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.