私の見解は--
def create_account(request):
if request.method == 'POST':
form = CreateAccountForm(request.POST)
if form.is_valid():
acc_act_date = form.cleaned_data['Account_Activation_Date']
present_date = date.today()
if acc_act_date <= present_date:
stat = 'Active'
else:
stat = 'Inactive'
a = Account_status.objects.get(status = stat)
sto = Create_account_tab(account_number=form.cleaned_data['Account_Number'],
account_name=form.cleaned_data['Account_Name'],
account_description=form.cleaned_data['Account_Description'],
account_status_key=a,
account_manager=form.cleaned_data['Account_Manager'],
parent_account_number=form.cleaned_data['Parent_Account_Number'],
account_activation_date=form.cleaned_data['Account_Activation_Date'],
)
sto.save()
return HttpResponseRedirect('/create_account/thanks/')
else:
form = CreateAccountForm()
return render_to_response('CreateAccountForm.html', {'form': form}, context_instance=RequestContext(request))
そして私の姿は--
class CreateAccountForm(forms.Form):
Account_Number = forms.CharField()
Account_Name = forms.CharField()
Account_Description = forms.CharField()
Account_Manager = forms.CharField()
Parent_Account_Number = forms.CharField(required = False)
Account_Activation_Date = forms.DateField()
そして私のテンプレートは--
<html>
<head>
<title>Your Information</title>
</head>
<body>
<h1>Fill in your details</h1>
{% if form.errors %}
<p style="color: red;">
Please correct the error{{ form.errors|pluralize }} below.
</p>
{% endif %}
<form action="." method="post">{% csrf_token %}
<div class="field">
{{ form.Account_Number.errors }}
<label for="id_Account_Number">Account Number:</label>
{{ form.Account_Number }}
</div>
<div class="field">
{{ form.Account_Name.errors }}
<label for="id_Account_Name">Account Name:</label>
{{ form.Account_Name }}
</div>
<div class="field">
{{ form.Account_Description.errors }}
<label for="id_Account_Description">Account Description:</label>
{{ form.Account_Description }}
</div>
<div class="field">
{{ form.Account_Manager.errors }}
<label for="id_Account_Manager">Account Manager:</label>
{{ form.Account_Manager }}
</div>
<div class="field">
{{ form.Parent_Account_Number.errors }}
<label for="id_Parent_Account_Number">Parent Account Number:</label>
{{ form.Parent_Account_Number }}
</div>
<div class="field">
{{ form.Account_Activation_Date.errors }}
<label for="id_Account_Activation_Date">Account Activation Date:</label>
{{ form.Account_Activation_Date }}
</div>
<input type="submit" value="Submit">
</form>
問題は、テンプレートで行った検証が機能しなくなり、エラーを生成すると、ビュー account.views.create_account が HttpResponse オブジェクトを返さなかったというdjango エラーが表示されることです。テンプレートから表示したいエラーの代わりに。:(誰でもこれで私を助けることができますか??