実際に何かを行うビューの書き込みセクションで立ち往生しています。指示に従って、ビューを次のように変更しました。
from django.template import Context, loader
from polls.models import Poll
from django.http import HttpResponse
def index(request):
latest_poll_list = Poll.objects.all().order_by('-pub_date')[:5]
t = loader.get_template('polls/index.html')
c = Context({
'latest_poll_list': latest_poll_list,
})
return HttpResponse(t.render(c))
def detail(request, poll_id):
return HttpResponse("You're looking at poll %s." % poll_id)
def results(request, poll_id):
return HttpResponse("You're looking at the results of the poll %s." % poll_id)
def vote(request, poll_id):
return HttpResponse("You're voting on poll %s." % poll_id)
テンプレート ディレクトリを/home/stanley/mytemplates/polls/
チュートリアルの指示どおりに作成しました。これは、次のファイルに一致する関連行ですsettings.py
。
TEMPLATE_DIRS = (
"/home/stanley/mytemplates/",
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
ただし、localhost でサーバーを実行した後も、ブラウザーに次のエラー メッセージが表示されます ( http://127.0.0.1:8000/polls/index.html
)。
Page not found (404)
Request Method: GET
Request URL: http://localhost:8000/polls/index.html
Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:
^polls/$
^polls/(?P<poll_id>\d+)/$
^polls/(?P<poll_id>\d+)/results/$
^polls/(?P<poll_id>\d+)/vote/$
^admin/
^admin/
The current URL, polls/index.html, didn't match any of these.
You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.
コードまたはファイルに何か問題がありますが、正確に何が原因かわかりません。