Djangosyncdb 找不到我的应用程序
我是 django 新手,一直遇到问题。
在我的项目根目录中,我创建了一个名为“local_apps”的文件夹,并在其中放置了应用程序“myapp”。我用以下内容更新了 settings.py 中的 INSTALLED_APPS: myproject.local_apps.myapp
但是,当我尝试同步 bd 时,Django 给出错误:“不存在名为 local_apps.myapp 的模块”
当我将“myapp”放回项目根目录时,它可以工作再说一次,但我不想那样。我想将我的应用程序保存在“local_apps”文件夹中。
你能告诉我我在这里做错了什么吗?
提前致谢。
I'm a django newbie and have been having a problem.
In my project root I created a folder called 'local_apps' and within it I put the app 'myapp'. I updated the INSTALLED_APPS within settings.py with: myproject.local_apps.myapp
However when I try to syncbd, Django gives an error: 'no module named local_apps.myapp exists'
When I put 'myapp' back in the project root, it works again but I dont want it that way. I want to keep my apps in the folder 'local_apps'.
Can you tell me what I am doing wrong here.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为这是一个通用的 python 错误,而不是 Django 错误。
也许您需要在 local_apps 目录中创建一个 __init__.py 文件,以便 python 知道它是一个模块。
I think that's a generic python error, not a Django error.
Maybe you need to create an
__init__.py
file in the local_apps directory, so python knows it's a module.myapp 文件夹中有
models.py
吗?我认为 Django 可能需要在应用程序中查看该文件。[编辑:实际上,我认为上面的wisty可能是对的,请确保你有一个
__init__.py
,如果有,请尝试使用models.py。]Do you have a
models.py
within the myapp folder? I think Django may need to see that file in the app.[Edit: actually, I think wisty above may be right, make sure you have an
__init__.py
, if you do, try the models.py.]我遇到了错误:
ImportError:没有名为 foo 的模块
为了解决这个问题,我只是将 Django 站点包添加到
settings.py
模块的 Python 路径中,如下所示:I was facing the error:
ImportError: No module named foo
To solve this, I just added the Django site package to the Python path at
settings.py
module like this: