Python 覆盖Django中不带模型的Textarea。仅在形式上
我想更改Textarea的默认大小。我读到: [ 但我不知道我怎么能推翻它 我的代码: forms.py:Python 覆盖Django中不带模型的Textarea。仅在形式上,python,django,Python,Django,我想更改Textarea的默认大小。我读到: [ 但我不知道我怎么能推翻它 我的代码: forms.py: from django import forms class KarForm(forms.Form): message = forms.CharField( widget=forms.Textarea, label="", ) views.py: from django.shortcuts import render from .for
from django import forms
class KarForm(forms.Form):
message = forms.CharField(
widget=forms.Textarea,
label="",
)
views.py:
from django.shortcuts import render
from .forms import KarelForm
def home(request):
form = KarForm()
context = {
"form": form
}
return render(request, "form.html", context)
选中。您可以添加类或其他属性,例如:
class CommentForm(forms.Form):
name = forms.CharField(widget=forms.TextInput(attrs={'class': 'special'})) # then you define the class in your css file
url = forms.URLField()
comment = forms.CharField(widget=forms.TextInput(attrs={'size': '40'}))
选中。您可以添加类或其他属性,例如:
class CommentForm(forms.Form):
name = forms.CharField(widget=forms.TextInput(attrs={'class': 'special'})) # then you define the class in your css file
url = forms.URLField()
comment = forms.CharField(widget=forms.TextInput(attrs={'size': '40'}))