質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Django

DjangoはPythonで書かれた、オープンソースウェブアプリケーションのフレームワークです。複雑なデータベースを扱うウェブサイトを開発する際に必要な労力を減らす為にデザインされました。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

解決済

1回答

3450閲覧

【Django】runserverの結果Page not found (404)とでてしまう

Renkon

総合スコア26

Django

DjangoはPythonで書かれた、オープンソースウェブアプリケーションのフレームワークです。複雑なデータベースを扱うウェブサイトを開発する際に必要な労力を減らす為にデザインされました。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2020/01/06 08:19

MNISTで学習済みのニューラルネットワークをもちいて手書きの数字を判定するアプリを作りたいです。
Djangoにふれるのは初めてで、ディレクトリの構造やアドレスの指定方法に悩んでいます。

構造は以下の通りです

tutorial │ db.sqlite3 │ manage.py │ trainMNIST.ipynb │ │ ├─config │ │ settings.py │ │ urls.py │ │ wsgi.py │ │ __init__.py │ │ │ └─__pycache__ │ settings.cpython-36.pyc │ urls.cpython-36.pyc │ wsgi.cpython-36.pyc │ __init__.cpython-36.pyc │ ├─mnist │ │ admin.py │ │ apps.py │ │ models.py │ │ tests.py │ │ urls.py │ │ views.py │ │ __init__.py │ │ │ ├─migrations │ │ │ __init__.py │ │ │ │ │ └─__pycache__ │ │ __init__.cpython-36.pyc │ │ │ └─__pycache__ │ admin.cpython-36.pyc │ models.cpython-36.pyc │ urls.cpython-36.pyc │ views.cpython-36.pyc │ __init__.cpython-36.pyc │ ├─NN │ best_weights.hdf5 │ history.csv │ trainMNIST.ipynb │ ├─static │ └─images │ sample1.jpg │ sample2.jpg │ sample3.jpg │ └─templates │ base.html │ └─mnist idex.html result.html

以上です。

python manage.py runserverを実行し、http://127.0.0.1:8000/に接続すると、以下のようなエラーが出てしまいます。

Using the URLconf defined in config.urls, Django tried these URL patterns, in this order: admin/ mnist/ The empty path didn't match any of these.

以上です。

config.urls.pyの中身はこの通りです。

python

1from django.contrib import admin 2from django.urls import path 3from django.conf.urls import include 4 5urlpatterns = [ 6 path('admin/', admin.site.urls), 7 # mnistアプリケーションのurls.pyをインクルード urls.pyはアプリケーションごとに作ると良い 8 path('mnist/', include('mnist.urls')), 9 ]

どう改善すればよろしいでしょうか。
どうぞよろしくお願いいたします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

対処1

http://127.0.0.1:8000/mnist/ ``` にアクセスしてください。 対処2 settings.pyのTEMPLATESでtemplatesディレクトリの位置を指定してください。 ```python TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [os.path.join(BASE_DIR, 'templates')], #templatesディレクトリの指定 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], }, }, ]

投稿2020/01/06 10:21

編集2020/01/07 02:18
tatamyiwathy

総合スコア1039

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

Renkon

2020/01/06 10:30

コメントありがとうございます。 ご指摘の通り、http://127.0.0.1:8000/mnist/に接続したのですがやはりうまくいきません。 mnist.urlsの中身は ''' from django.contrib import admin from django.urls import path from django.views.generic import TemplateView from . import views urlpatterns = [ #TemplateViewを使ってTOPページ(index.html)を定義 path('', TemplateView.as_view(template_name='templates/mnist/index.html'), name='index'), #ボタンが押されたときに呼ばれるuploadのURLパターンを定義 path('upload/', views.upload, name='upload'), ] ''' となっております。
tatamyiwathy

2020/01/06 10:34 編集

エラーの全体を見せていただけますか?
Renkon

2020/01/06 10:40

TemplateDoesNotExist at /mnist/ templates/mnist/index.html Request Method: GET Request URL: http://127.0.0.1:8000/mnist/ Django Version: 2.2.5 Exception Type: TemplateDoesNotExist Exception Value: templates/mnist/index.html Exception Location: C:\Users\AppData\Local\Continuum\anaconda3\envs\django\lib\site-packages\django\template\loader.py in select_template, line 47 Python Executable: C:\Users\AppData\Local\Continuum\anaconda3\envs\django\python.exe Python Version: 3.6.9 Python Path: ['C:\Users\Documents\Python Scripts\LBS\django\tutorial', 'C:\Users\AppData\Local\Continuum\anaconda3\envs\django\python36.zip', 'C:\Users\AppData\Local\Continuum\anaconda3\envs\django\DLLs', 'C:\Users\AppData\Local\Continuum\anaconda3\envs\django\lib', 'C:\Users\AppData\Local\Continuum\anaconda3\envs\django', 'C:\Users\AppData\Local\Continuum\anaconda3\envs\django\lib\site-packages', 'C:\Users\AppData\Local\Continuum\anaconda3\envs\django\lib\site-packages\win32', 'C:\Users\AppData\Local\Continuum\anaconda3\envs\django\lib\site-packages\win32\lib', 'C:\Users\AppData\Local\Continuum\anaconda3\envs\django\lib\site-packages\Pythonwin'] Server time: 月, 6 1月 2020 19:36:28 +0900 Template-loader postmortem Django tried loading these templates, in this order: Using engine django: django.template.loaders.app_directories.Loader: C:\Users\AppData\Local\Continuum\anaconda3\envs\django\lib\site-packages\django\contrib\admin\templates\templates\mnist\index.html (Source does not exist) django.template.loaders.app_directories.Loader: C:\Users\AppData\Local\Continuum\anaconda3\envs\django\lib\site-packages\django\contrib\auth\templates\templates\mnist\index.html (Source does not exist) この通りです。 どうぞよろしくお願いいたします。
tatamyiwathy

2020/01/07 01:40

templateファイルの検索に失敗してますね。settings.pyのTEMPLATES = []はどのようになってますでしょうか。
Renkon

2020/01/07 01:49

TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], }, }, ] このようにしてあります。
Renkon

2020/01/07 04:03

ご回答ありがとうございます! ただ、またもや同様なエラーが出てしまいました。 TemplateDoesNotExist at /mnist/ templates/mnist/index.html Request Method: GET Request URL: http://127.0.0.1:8000/mnist/ Django Version: 2.2.5 Exception Type: TemplateDoesNotExist Exception Value: templates/mnist/index.html ここでのtemplates/mnist/index.htmlというのは、プロジェクトのディレクトリ直下のものを指定できているのでしょうか?
tatamyiwathy

2020/01/08 05:32

templates/mnist/index.htmlは存在してますか? idex.htmlになっていませんか?
Renkon

2020/01/09 03:01

実はそのミスに気が付いていたので名前の付け直しをしたのですが、 このエラーが出てきたので不可解におもっておりました。
Renkon

2020/01/09 08:51

tutorial/mnist/urls.pyにおけるtemplateのしていが間違っていたようです。 urlpatterns = [ #TemplateViewを使ってTOPページ(index.html)を定義 path('', TemplateView.as_view(template_name='mnist/index.html'), name='index'), #ボタンが押されたときに呼ばれるuploadのURLパターンを定義 path('upload/', views.upload, name='upload'), ] として解決いたしました。 ありがとうございました!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問