i'm trying import models django project project. found 2 solutions: first using os.environ['pythonpath'] , second using sys.path.append(). project structure:
-project1(django project)
- mysite
- settings.py
- ...
- app1
- models.py
- ...
project2(no django project)
- test
- dog.py
and in dog.py file:
import sys import os sys.path.append("/home/jack/workspace/project1/mysite") os.environ['django_settings_module'] ="mysite.settings" app1 import models
but console show me:
from app1 import models importerror: no module named app1
from drawing, app1
sibling mysite
—that is, it's in /home/jack/workspace/project1/app1/
, not /home/jack/workspace/project1/mysite/app1/
.
so, sys.path.append("/home/jack/workspace/project1/mysite")
isn't going good; need `sys.path.append("/home/jack/workspace/project1/")'.
Comments
Post a Comment