Posted at

Django1.9 環境非依存のwsgi.pyの書き方

More than 3 years have passed since last update.

よくこういう書き方してるけど、


wsgi.py

import os

import sys

from django.core.wsgi import get_wsgi_application

sys.path.append("/path/to/project/hoge")
sys.path.append("/path/to/project/hoge/hoge")

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

application = get_wsgi_application()


こう書けば環境が変わっても使えるっぽい。


wsgi.py

import os

import sys

from django.core.wsgi import get_wsgi_application

FILE_PATH = os.path.dirname(__file__)
PROJECT_NAME = os.path.basename(FILE_PATH)

sys.path.append(os.path.dirname(FILE_PATH))
sys.path.append(FILE_PATH)

os.environ.setdefault("DJANGO_SETTINGS_MODULE", PROJECT_NAME + ".settings")

application = get_wsgi_application()