9
6

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 5 years have passed since last update.

Apacheとdjangoを連携させたいがNo module named プロジェクト名 とでてしまう

Last updated at Posted at 2019-02-25

apache経由でdjangoにアクセスすると、
Internal Server Error。

ログを確認すると、

No module named プロジェクト名

という感じででている。
試しに直接、

python wsgi.py

と叩いてみてもやはりモジュールが見つからないと怒られる。

泣きながら、

wsgi.pyに

import sys
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/..')

を追記してみたところなんとか動いた。

これで正しいのかどうかわからないがこれでいいのだ。

最終的なwsgi.pyは、

import os

from django.core.wsgi import get_wsgi_application
from dj_static import Cling

import sys
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/..')


os.environ.setdefault("DJANGO_SETTINGS_MODULE", "projectname.settings")


application = Cling(get_wsgi_application())

こんな感じ。

9
6
1

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
9
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?