いくつかの選択肢を使ってフォームを作成して表示したいと思います。しかし、出力htmlでは、フォーム自体は表示されませんでした。これが私のファイルです:
views.py:
from django.http import HttpResponse, Http404
from django.shortcuts import render_to_response
from tasks.todoes.models import Note, Resource,/
File, Worker, Client, Task, ProblemByWorker, ProblemByUser, Categories
from tasks.forms import NewTicketForm
def new_ticket2(request):
method = request.method
if request.method == 'POST':
form = NewTicketForm(request.POST)
if form.is_valid():
pass
else:
form = NewTicketForm()
return render_to_response('new_ticket2.html', {'form':form, 'method':method})
forms.py
from django import forms
from tasks.todoes.models import Note, Resource, File, Worker, Client, Task,/
ProblemByWorker, ProblemByUser, Categories
class NewTicketForm(forms.Form):
name = forms.CharField(max_length=140)
pbus = forms.ChoiceField(choices = ProblemByUser.objects.all())
description = forms.CharField(widget=forms.Textarea)
clients = forms.ChoiceField(choices = Client.objects.all())
priority = forms.ChoiceField(choices = ('1','2','3','4','5'))
category = forms.ChoiceField(choices = Categories.objects.all())
start_date = forms.DateTimeField()
due_date = forms.DateTimeField()
workers = forms.ChoiceField(choices = Worker.objects.all())
percentage = forms.DecimalField(min_value=0, max_value=100)
new_ticket2.html
<html>
<head>
<title>New Ticket</title>
</head>
<body>
{% if form.errors %}
{{form.errors}}
{% endif %}
<p>{{ method }}</p>
<form action="" method="post">
<table>
{{ form.as_table }}
</table>
<input type="submit">
</form>
</body>
私の出力では、「GET」と送信ボタンのみが表示されます。
<html><head>
<title>New Ticket</title>
...</head>
<body>
<p>GET</p>
<form action="" method="post">
<table>
</table>
<input type="submit">
</form>
...</body></html>
なぜそうなのか?