前提・実現したいこと
Python: 3.6.6
Django: 2.1
Linux: 4.15.0-29-generic
ubuntu: 18.04.1 LTS
Firefox: 62.0.3
Djangoで作成したWebアプリケーションを、Linux上に立てたDockerで動かし、Firefoxで表示しています。
settings.py に正しくstatic ディレクトリを設定できた場合、
「http://localhost:8000/static/ファイル名」でアクセスできるようですが、エラーが出てしまいます。
エラー文の「Directory indexes」が何かがわかりません。
解決法は調べてはみましたが、自分の settings.py の内容が間違っているように見えず、お手上げです。
ご教示よろしくお願い致します。
発生している問題・エラーメッセージ
http://localhost:8000/static/ にアクセスした場合
Page not found (404) Request Method: GET Request URL: http://localhost:8000/static/ Directory indexes are not allowed here. 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.
http://localhost:8000/static/pycharm.png にアクセスした場合
Page not found (404) Request Method: GET Request URL: http://localhost:8000/static/pycharm.png 'pycharm.png' could not be found 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.
該当のソースコード
config/settings.py
BASE_DIR = '/home/ユーザ名/PycharmProjects/mysite2/mysite2' PROJECT_NAME = 'mysite2' STATIC_URL = '/static/' STATICFILES_DIRS = [os.path.join(BASE_DIR, '/static')] STATIC_ROOT = '/var/www/{}/static'.format(PROJECT_NAME)
config/urls.py(追記)
urlpatterns = [ ・・・略・・・ ] urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
試したこと
python3 manage.py collectstatic
を実行して、「/var/www/mysite2/static」に「pycharm.png」があることを確認。
DEBUF = True を
DEBUG = False
に変更して http://localhost:8000/static/ にアクセスした場合、
http://localhost:8000/static/pycharm.png にアクセスした場合共に
Not Found The requested URL /static/ was not found on this server.
dockerに関して(追記)
docker の起動方法
VirtualBox:~$ docker start mysite2 VirtualBox:~$ docker attach mysite2 VirtualBox:~$ docker attach mysite2 root@63e19d771435:~/mysite2# cd mysite2 root@63e19d771435:~/mysite2/mysite2# python3 manage.py runserver 0.0.0.0:8000 Performing system checks... System check identified no issues (0 silenced). October 17, 2018 - 02:39:11 Django version 2.1, using settings 'config.settings' Starting development server at http://0.0.0.0:8000/ Quit the server with CONTROL-C.
docker ps の結果
VirtualBox:~$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 63e19d771435 mysite2:1.0 "/bin/bash" 13 days ago Up 1 second 0.0.0.0:8000->8000/tcp mysite2

回答1件
あなたの回答
tips
プレビュー