我有一個從應用程序導入models.py的腳本,但它不會導入! 我不相信我應該手動創建一個「導出DJANGO ...」環境變量......我正在做其他的錯誤。爲什麼我在Django中出現這個錯誤?
Traceback (most recent call last):
File "parse.py", line 8, in ?
from butterfly.flower.models import Channel, Item
File "/home/user/shri/butterfly/flower/models.py", line 1, in ?
from django.db import models
File "/usr/lib/python2.4/site-packages/django/db/__init__.py", line 10, in ?
if not settings.DATABASE_ENGINE:
File "/usr/lib/python2.4/site-packages/django/utils/functional.py", line 269, in __getattr__
self._setup()
File "/usr/lib/python2.4/site-packages/django/conf/__init__.py", line 38, in _setup
raise ImportError("Settings cannot be imported, because environment variable %s is undefined." % ENVIRONMENT_VARIABLE)
ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.
感謝。那麼,在設置一個Django項目之後,是否有必要設置2個環境變量? -DJANGO_SETTINGS_MODULE -PYTHONPATH ..加上項目路徑。 – TIMEX
大聲笑,我認爲你從字面上看「我不相信」。 – hasen
@hasen,猜我對任何名叫「alex」的人都有很高的期望;-)。 –