前提・実現したいこと
djangoの初心者です。
公式チュートリアルで躓きました。
当該ページ
チュートリアルに従い、開発用サーバーを立て、
pollsという名称のHelloWorld表示アプリを作成、実行したところ、
404エラーとなってしまいました。
初歩の初歩でお恥ずかしい限りですが、
ご教示頂けますと幸いです。
発生している問題・エラーメッセージ
エラー文からすると、
ブラウザに打ち込んだurlと対比するための候補データ(=urlpatternの中身)がadminとpollsの2つあるはずなのに、
adminしか読み込めていないように思います。
Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8000/polls/ Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order: admin/ The current path, polls/, 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.
該当のソースコード
python
1ファイル名:polls/views.py 2from django.http import HttpResponse 3 4def index(request): 5 return HttpResponse("Hello,world. You're at the polls index.")
python
1ファイル名:mysite/urls.py 2from django.contrib import admin 3from django.urls import include,path 4urlpatterns = [ 5 path('polls/', include('polls.urls')), 6 path('admin/', admin.site.urls), 7]
python
1ファイル名:polls/urls.py 2from django.urls import path 3from . import views 4urlpatterns = [ 5 path('', views.index, name='index'), 6]
ファイル名:manage.py
試したこと
- フォルダ構成を確認した。
env1/
. Lib/ (中身は略)
. Scripts/ (中身は略)
. pyvenv.cfg
. mysite/
. pycache/
. mysite/
. init.py
. asgi.py
. settings.py
. urls.py
. wsgi.py
. polls/
. pycache/
. migrations/
. init.py
. admin.py
. apps.py
. models.py
. tests.py
. urls.py
. views.py
. db.sqlite3
. manage.py
. urls.py
- コマンドプロンプトで python manage.py runserver を実行した。
- 以下の順にアクセスした。
・http://127.0.0.1:8000/ (サーバへのアクセス) ⇒アクセスできた。
・http://127.0.0.1:8000/admin/ (ログインページへのアクセス) ⇒アクセスできた。
・http://127.0.0.1:8000/polls/ (HelloWorld記載ページへのアクセス)⇒404エラー
- mysite/urls.py の、urlpatternの記法を確認した。
'polls/$'でもアクセス出来ず。
補足情報(FW/ツールのバージョンなど)
python 3.8.3
django 3.0.6
vscode
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。