0
我有一個Django形式設置如下:額外的表單字段在Django的形式添加渲染
forms.py
class TestimonialForm(forms.ModelForm):
name = forms.CharField(widget=forms.TextInput(attrs={'class': 'form-control'}))
designation = forms.CharField(widget=forms.TextInput(attrs={'class': 'form-control'}))
testimonial = forms.CharField(widget=forms.Textarea(attrs={'class': 'form-control test-form-area'}))
class Meta:
model = Testimonials
models.py
class Testimonials(models.Model):
name = models.CharField(max_length=128)
test = models.CharField(max_length=2000)
credentials = models.CharField(max_length=128)
def __unicode__(self):
return self.name
views.py
def add_testimonial(request):
context = RequestContext(request)
if request.method == 'POST':
form = TestimonialForm(request.POST)
if form.is_valid():
form.save(commit=True)
return index(request)
else:
print form.errors
else:
form = TestimonialForm()
return render_to_response('/add_testimonial.html', {'form': form}, context)
在呈現,我看到三個主要領域臨t我在forms.py中定義了將form控件添加到它們的類。但是,我也看到兩個沒有附加樣式的額外字段。任何想法出了什麼問題?