私は最初の Django フォームを利用しようとしていますが、主にこの例に従っています。自分で明示的な HTML フォームを提供する必要がありますか? それとも、Django の Form クラスがこれを行ってくれますか? もしそうなら、どのように?
これが私の現在のエラーです:
Internal Server Error: /showCrime/query
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/django/core/handlers/base.py", line 115, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "/Users/rik/Code/eclipse/djOakData/showCrime/views.py", line 43, in getQuery
return render(request, 'getQuery.html', {'form': qform})
File "/Library/Python/2.7/site-packages/django/shortcuts/__init__.py", line 53, in render
return HttpResponse(loader.render_to_string(*args, **kwargs),
File "/Library/Python/2.7/site-packages/django/template/loader.py", line 170, in render_to_string
t = get_template(template_name)
File "/Library/Python/2.7/site-packages/django/template/loader.py", line 146, in get_template
template, origin = find_template(template_name)
File "/Library/Python/2.7/site-packages/django/template/loader.py", line 139, in find_template
raise TemplateDoesNotExist(name)
TemplateDoesNotExist: getQuery.html
showCrime/views.getQuery():
def getQuery(request):
# import pdb; pdb.set_trace()
if request.method == 'POST':
qform = simpleQ(request.post)
if qform.is_valid():
qryData = qform.cleaned_data
simpleQ.NQUERY += 1
qurl = 'showCrime/plots/%s+%s.png' % (qryData['beat'], qryData['crimeCat'])
return HttpResponseRedirect(qurl)
else:
qform = simpleQ()
return render(request, 'getQuery.html', {'form': qform})
showCrime/templates/showCrime/getQuery.html
<html>
<head>
<title>ShowCrime - Query</title>
</head>
<body>
<h1>ShowCrime - Query</h1>
{% if form.errors %}
<p style="color: red;">
Please correct the error{{ form.errors|pluralize }} below.
</p>
{% endif %}
<form action="/getQuery/" method="post">
<table>
{{ form.as_table }}
</table>
{% csrf_token %}
<input type="submit" value="Submit query">
</form>
</body>
</html>