Django での static files の扱い方まとめ (追加)
以前書いたPOST の中で避けてたw点、よい解決方法が見つかったのでメモ。
400.html, 500html などの動作確認を行いたいなーって思って。Django1.8.17で確認しました。
元POST : Django での static files の扱い方まとめ - AWS / PHP / Python ちょいメモ
ちなみに、開発サーバーでも、次の条件が揃うと、 {{ STATIC_URL }} が自動公開されなくなります。
settings.py : DEBUG="False" & ALLOWED_HOSTS = ['something'] のケース
settings.py : DEBUG="Ture" & runserver —nostaticオプション付 で起動
DEBUG="False"の時にも urls.py の設定で、static files を公開する方法もあり(ググってください)
DEBUG="False" の時に Static files を公開する簡単な方法:
$ python manage.py runserver --insecure
runserver に insecure オプションがあるんですね。
--insecure Allows serving static files even if DEBUG is False.
その他
$ python3 manage.py help runserver
usage: manage.py runserver [-h] [--version] [-v {0,1,2,3}]
[--settings SETTINGS] [--pythonpath PYTHONPATH]
[--traceback] [--no-color] [--ipv6] [--nothreading]
[--noreload] [--nostatic] [--insecure]
[addrport]Starts a lightweight Web server for development and also serves static files.
positional arguments:
addrport Optional port number, or ipaddr:portoptional arguments:
-h, --help show this help message and exit
--version show program's version number and exit
-v {0,1,2,3}, --verbosity {0,1,2,3}
Verbosity level; 0=minimal output, 1=normal output,
2=verbose output, 3=very verbose output
--settings SETTINGS The Python path to a settings module, e.g.
"myproject.settings.main". If this isn't provided, the
DJANGO_SETTINGS_MODULE environment variable will be
used.
--pythonpath PYTHONPATH
A directory to add to the Python path, e.g.
"/home/djangoprojects/myproject".
--traceback Raise on CommandError exceptions
--no-color Don't colorize the command output.
--ipv6, -6 Tells Django to use an IPv6 address.
--nothreading Tells Django to NOT use threading.
--noreload Tells Django to NOT use the auto-reloader.
--nostatic Tells Django to NOT automatically serve static files
at STATIC_URL.
--insecure Allows serving static files even if DEBUG is False.