0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

manage.py collectstatic時のエラー

Last updated at Posted at 2021-06-01

##はじめに
djangoで作ったアプリのファイルをAWS上に配置しようとした際に発生したエラーです。
間違っている点あればご指摘ください。

##エラー内容

EC2にSSH接続した後に仮想環境をアクティベートの状態でmanage.pyのあるディレクトリで

ターミナル
python manage.py collectstatic

コマンドを入力すると

Traceback (most recent call last):
  File "/home/app_admin/venv_private_diary/lib/python3.7/site-packages/django/core/management/__init__.py", line 237, in fetch_command
    app_name = commands[subcommand]
KeyError: 'collectstatic'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "manage.py", line 21, in <module>
    main()
  File "manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "/home/app_admin/venv_private_diary/lib/python3.7/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "/home/app_admin/venv_private_diary/lib/python3.7/site-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/app_admin/venv_private_diary/lib/python3.7/site-packages/django/core/management/__init__.py", line 244, in fetch_command
    settings.INSTALLED_APPS
  File "/home/app_admin/venv_private_diary/lib/python3.7/site-packages/django/conf/__init__.py", line 82, in __getattr__
    self._setup(name)
  File "/home/app_admin/venv_private_diary/lib/python3.7/site-packages/django/conf/__init__.py", line 69, in _setup
    self._wrapped = Settings(settings_module)
  File "/home/app_admin/venv_private_diary/lib/python3.7/site-packages/django/conf/__init__.py", line 170, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/lib64/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'private_diary'

のエラーが発生してしまいました。

##原因
settings.py内のINSTALLED_APPSのリストにprivate_diaryを追加していなかったことが原因。

##注意点
上記の原因を変更した後にローカルリポジトリにコミットしてリモートリポジトリにプッシュしてからgit pullコマンドで変更内容を適用してください。私はコミットするのを忘れてしまい問題解決できず堂々巡りしてしまいました。
またpython manage.py collectstaticする際は仮想環境にアクティベートしていないと

File "manage.py", line 16
    ) from exc
         ^
SyntaxError: invalid syntax

上記のエラーが発生してしまうので気をつけてください。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?