我想用一些选择制作一个表格并显示它。但是在输出 html 中我没有看到表单本身。这是我的文件:
视图.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})
表格.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>
为什么这样?