###前提・実現したいこと
DjangoでStaticの設定をしたいです。
具体的にはCSSにアクセスし、読み込みができるようにしたいです。
そこで、いろいろなチュートリアルや、ドキュメントを一応は参照させていただいたのですが、どうやっても404になってしまい、アクセスできません。
何が悪いでしょうか。
###該当のソースコード
settings.py
標準のまま特に変えてません。
python
1# Static files (CSS, JavaScript, Images) 2# https://docs.djangoproject.com/en/1.11/howto/static-files/ 3 4STATIC_URL = '/static/'
ファイル構造
とにかく目的のCSSをばらまいてみました。
bash
1# pwd 2/opt/oth 3# find -type f 4./manage.py 5./oth/wsgi.py 6./oth/__init__.py 7./oth/settings.py 8./oth/style.css 9./oth/static/style.css 10./oth/static/common/css/style.css 11./oth/static/common/style.css 12./oth/urls.py 13./style.css 14./static/style.css 15./static/common/css/style.css 16./static/common/style.css
###試したこと
どんなURLだったらアクセスできるのか?
{% static }で生成されるであろうURL(もちろん実際に生成されたURLも含みます)を作成し、curlコマンドにして実行してみました。
bash
1$ cat style_access 2curl -o /dev/null -w '%{http_code}\n' -s http://appserver/static/style.css 3curl -o /dev/null -w '%{http_code}\n' -s http://appserver/static/common/style.css 4curl -o /dev/null -w '%{http_code}\n' -s http://appserver/static/common/css/style.css 5curl -o /dev/null -w '%{http_code}\n' -s http://appserver/static/css/style.css 6curl -o /dev/null -w '%{http_code}\n' -s http://appserver/static/oth/css/style.css 7curl -o /dev/null -w '%{http_code}\n' -s http://appserver/static/oth/common/css/style.css 8$ 9$ bash style_access 10404 11404 12404 13404 14404 15404
###補足情報(言語/FW/ツール等のバージョンなど)
UbuntuServer 16.04LTS
Python 3.5.2
Django 1.11.4
プロジェクトROOT: /opt/oth
アプリケーションROOT: /opt/oth/oth
WSGI
bash
1# cat /etc/apache2/conf-enabled/rjb.conf 2WSGIScriptAlias / /opt/oth/oth/wsgi.py 3WSGIPythonPath /opt/oth/ 4 5<Directory /opt/oth/oth/> 6<Files wsgi.py> 7 Require all granted 8</Files> 9</Directory>
今回はわかりやすくとにかくCSSだけにアクセスするために最小限に絞ってテストしました。
実際のVIEWなどは表示されています。
データベースの接続等も問題ありませんでした。
Staticの設定だけがNot Foundになってしまい、デザイン崩れして困っています。
Djangoはバッチ用途ではよく使うのですが、WEBは初めてで勝手がわかりません。
よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/08/21 23:59