公式チュートリアルをみつつDjangoを勉強しています。
その際にルートを追加し、ページで文字を表示する事を行いたいのですが、404エラーとなるため
どなたか対応方法をご教授いただければと存じます。
環境
Djang 2系
Pythin 3系
接続したい URL:http://localhost:8000/polls/test
エラー
Not Found: /polls/test "GET /polls/test HTTP/1.1" 404 2905
編集パス:mysite/polls/urls.py
from django.urls import path from . import views urlpatterns = [ path('', views.index, name='index'), path(r'^test', views.test, name='test'), ]
編集パス:mysite/polls/views.py
from django.http import Http404 from django.shortcuts import get_object_or_404, render from .models import Question def results(request, question_id): response = "You're looking at the results of question %s." return HttpResponse(response % question_id) def index(request): latest_question_list = Question.objects.order_by('-pub_date')[:5] context = {'latest_question_list': latest_question_list} return render(request, 'polls/index.html', context) def test(request): return render(request, 'polls/test.html')
編集パス:mysite/urls.py
from django.urls import path from . import views urlpatterns = [ # ファイル名.処理メソッド名 path('', views.index, name='index'), # added the word 'specifics' path('<int:question_id>/results/', views.results, name='results'), path(r'^test', views.test, name='test'), ]
編集パス polls/templates/polls/test.html
テスト
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。