django dev server (manage.py runserver) 从哪里获取它的路径?
我最近将一个 django 应用程序从 c:\Users\user\django-projects\foo\foobar
移动到 c:\Python25\Lib\site-packages\foo\foobar
(位于 python 路径上)。我在 django-projects 目录中启动了一个新应用,并将 foo.foobar 添加到 INSTALLED_APPS 设置中。当我尝试为新应用程序运行开发服务器 (manage.py runserver
) 时,收到错误ImportError: No module named foobar
。
查看回溯,它在 c:\Users\user\django-projects\foo\..\foo\foobar
中查找 foobar
应用程序。我检查了我的 PATH 和 PYTHONPATH 环境变量,它们都没有指向 c:\Users\user\django-projects\foo 并且它没有当我运行 python 解释器时,它会出现在 sys.path 中。
我猜我在 foo
开发过程中以某种方式将 c:\Users\user\django-projects\foo
添加到了 django 的路径中,但我不记得我是如何添加的做到了。
因此,有了这些,我的问题是“如何让manage.py在c:\Python25\Lib\site-packages而不是c:\Users\user\中查找django-projects\foo?”
谢谢,
- 莱克索
I recently moved a django app from c:\Users\user\django-projects\foo\foobar
to c:\Python25\Lib\site-packages\foo\foobar
(which is on the python path). I started a new app in the django-projects
directory, and added foo.foobar
to the INSTALLED_APPS
setting. When I try to run the dev server (manage.py runserver
) for my new app, I get the error ImportError: No module named foobar
.
Looking through the traceback, it's looking in the c:\Users\user\django-projects\foo\..\foo\foobar
for the foobar
app. I checked my PATH
and PYTHONPATH
environment variables, and neither point to c:\Users\user\django-projects\foo
and It doesn't show up in sys.path
when I run the python interpreter.
I'm guessing I somehow added c:\Users\user\django-projects\foo
to django's path sometime along the development of foo
but I don't remember how I did it.
So, with all that lead up, my question is "how do I make manage.py look in c:\Python25\Lib\site-packages
instead of c:\Users\user\django-projects\foo
?"
Thanks,
- Lexo
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
manage.py
从当前目录导入settings.py,并将settings
作为参数传递给execute_manager
。您可能在 settings.py 中定义了项目根目录。manage.py
imports settings.py from the current directory and passsettings
as parameter toexecute_manager
. You probably defined project root in settings.py.我修复了它,尽管我不知道哪种解决方案有效。首先,我从项目中删除了
.pyc
文件,然后重新索引了我的 Windows 搜索(我猜这就是这样做的)。这将错误消息更改为正确的目录。之后,我意识到我的 foobar/baz/models.py 文件中存在这个文件,这一直导致问题。我将其更改为
解决了问题。感谢劳伦特的帮助:-)
I fixed it, although I don't know which solution worked. First, I deleted the
.pyc
files from my project, then I reindexed my Windows search (I'm guessing this did it). This changed the error message to the correct directory. After which, i realized I hadin my
foobar/baz/models.py
file, which was causing the problem all along. I changed this towhich fixed the problem. Thanks to laurent for all your help :-)