[英]Django project folder structure
I am trying to organize my django project structure as: 我正在尝试将我的django项目结构组织为:
- myproject
-- manage.py
-- main_application
-- third_party
--- tastypie
But when i put tastypie in third_party folder and add it to installed applications with 'third_party.tastypie' tastypie models.py gives error: 但是,当我将tastypie放入third_party文件夹并将其添加到已安装的应用程序时,使用'third_party.tastypie'tastypie models.py会出错:
from tastypie.utils import now
ImportError: No module named 'tastypie'
How can i fix this issue without touching to tastypie models.py code? 如何在不触及tastypie models.py代码的情况下解决此问题?
It seems that you're organising your environment wrong. 您似乎正在组织环境错误。 Try using virtualenv . 尝试使用virtualenv 。 It gives you a nice way to isolate all of your project dependancies, so you can pip install tastypie
inside a virtualenv, which will put tastypie in the correct location for every app inside that environment to find. 它为您提供了一种隔离所有项目依赖性的好方法,因此您可以在virtualenv中pip install tastypie
,这样可以将tastypie放置在该环境中要查找的每个应用程序的正确位置。 I strongly recommend this solution. 我强烈推荐这个解决方案。
On a side note and if you insist on not using virtualenv: you should either add /path/to/byproject/third_party
to sys.path
or add an empty __init__.py
to your third_party
directory and import it like from third_party.tastypie.utils import now
如果您坚持不使用virtualenv:您应该将/path/to/byproject/third_party
添加到sys.path
或将空__init__.py
添加到您的third_party
目录并from third_party.tastypie.utils import now
导入它from third_party.tastypie.utils import now
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.