0
我在外部网关脚本中使用Django DB模块时遇到问题。 我有下 myproject的以下Python文件/所有MyApplication/lib.py由于设置模块加载,Django DB模块的外部使用失败
#<path>/myproject/myapplication/lib.py
from django.db import connection
from django.db import settings
#SOME METHODS ARE HERE
,其使用Django分贝模块
。
我需要进口LIB在另一个python脚本同一目录下的myproject /所有MyApplication/gateway.py
#<path>/myproject/myapplication/gateway.py
import sys, os
os.environ['DJANGO_SETTINGS_MODULE'] = "myproject.settings"
sys.path.append('../')
import lib
#SOME LOGIC HERE
,但它与下面的错误而失败:
Fisbrok:myproject firas$ python myapplication/gateway.py
Traceback (most recent call last):
File "myapplication/gateway.py", line 7, in ?
import lib
File ".... lib.py", line 1, in ?
from django.db import connection
File "/opt/local/lib/python2.4/site-packages/django/db/__init__.py", line 14, in ?
if not settings.DATABASES:
File "/opt/local/lib/python2.4/site-packages/django/utils/functional.py", line 276, in __getattr__
self._setup()
File "/opt/local/lib/python2.4/site-packages/django/conf/__init__.py", line 40, in _setup
self._wrapped = Settings(settings_module)
File "/opt/local/lib/python2.4/site-packages/django/conf/__init__.py", line 75, in __init__
raise ImportError("Could not import settings '%s' (Is it on sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, e))
ImportError: Could not import settings 'myproject.settings' (Is it on sys.path? Does it have syntax errors?): No module named myproject.settings
我错过了什么吗?