2.

CommandError: You must set settings.ALLOWED_HOSTS if DEBUG is False.

編集
この記事の要点
  • Django の CommandError: You must set settings.ALLOWED_HOSTS if DEBUG is False.
  • 原因: 本番モード (DEBUG=False) で ALLOWED_HOSTS 未設定
  • 対処: settings.pyALLOWED_HOSTS = ['example.com', 'www.example.com'] を追加
  • ワイルドカード ['*']セキュリティ上推奨されない

 

エラー内容

CommandError: You must set settings.ALLOWED_HOSTS if DEBUG is False.

 

発生条件/原因/対処法

settings.pyにてDEBUGFalseにも関わらずALLOWED_HOSTSが設定されていない場合に発生するエラー。

以下のように設定すればよい。

DEBUG = False

# ALLOWED_HOSTS=['*']

ALLOWED_HOSTS=['127.0.0.1', 'localhost']

 

編集
Post Share
子ページ

子ページはありません

同階層のページ
  1. Invalid HTTP_HOST header: '...'. You may need to add '...' to ALLOWED_HOSTS
  2. CommandError: You must set settings.ALLOWED_HOSTS if DEBUG is False.
  3. django.utils.datastructures.MultiValueDictKeyError
  4. Forbidden (403) CSRF verification failed. Request aborted.
  5. ModuleNotFoundError: No module named 'MySQLdb'
  6. WARNINGS: ?: (mysql.W002) MySQL Strict Mode is not set for database connection
  7. Unknown column 'table_name.id' in 'field list'
  8. RuntimeError: Model class ~ doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
  9. get() returned more than one MynumberRegist -- it returned 2!
  10. django.db.utils.OperationalError: (2006, "Can't connect to MySQL server")
  11. 'include' is not defined