我創建了一個形式,但監守對齊問題我試着對準自己在我的模板,Django表單對準
Forms.py
class VolunteerForm(forms.ModelForm):
volposition = forms.CharField(label="Volunteer Position")
roledesc = forms.CharField(label="Role Description")
noofhours = forms.IntegerField(label="Time requirements")
Qualreqt = forms.CharField(label="Qualifications and Requirements")
class Meta:
model = Volunteer
views.py
def volunteer_page(request):
#import pdb
pdb.set_trace()
if request.method == 'POST':
form = VolunteerForm(request.POST)
if form.is_valid():
f = form.save(commit=False)
f.save()
message = "Position added"
return HttpResponseRedirect('.')
else:
form = VolunteerForm()
variable = RequestContext(request,{'form':form})
return render_to_response('registration/volunteer.html',variable)
Volunteer.html
{% extends "base.html" %}
{% block title %}User Registration{% endblock %}
{% block head %}User Registration{% endblock %}
{% block content %}
<form method="post" action".">
<table border="0">
<tr>
{{ form.non_field_errors }}
<div class="fieldWrapper">
{{ form.volposition.errors }}
<th><label for="id_volposition">Volunteer Position</label></th>
<th>{{ form.volposition }}<maxlength="100"></th>
</div>
</tr>
<tr>
<div class="fieldWrapper">
{{ form.roledesc.errors }}
<th><label for="id_roledesc">Role Description:</label></th>
<th>{{ form.roledesc }}</th>
</div>
</tr>
<tr>
<div class="fieldWrapper">
{{ form.noofhours.errors }}
<th><label for="id_noofhours">Number of Hours:</label></th>
<th>{{ form.noofhours }}</th>
</div>
</tr>
<tr>
<div class="fieldWrapper">
{{ form.qualreqt.errors }}
<th><label for="id_qualreqt">Qualification and Requirements</label></th>
<th>{{ form.Qualreqt }}</th>
</div>
</tr>
</table>
<input type="submit" value="register" />
</form>
{% endblock %}
The角色描述和資格/要求應該有比這個頁面生成的html更大的文本區域
我的更改會是什麼?
可能的重複[改變用Django中的ModelForm創建的表單元素的寬度](http://stackoverflow.com/questions/110378/change-the-width-of-form-elements-created- with-modelform-in-django) – bernie 2012-03-25 22:33:32