Djangosyncdb 找不到我的应用程序

发布于 2024-10-19 13:18:04 字数 334 浏览 8 评论 0原文

我是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

鸠魁 2024-10-26 13:18:04

我认为这是一个通用的 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.

风启觞 2024-10-26 13:18:04

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.]

筱果果 2024-10-26 13:18:04

我遇到了错误:ImportError:没有名为 foo 的模块

为了解决这个问题,我只是将 Django 站点包添加到 settings.py 模块的 Python 路径中,如下所示:

PKG_DIR = os.path.dirname(__file__)
sys.path.append(PKG_DIR)

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:

PKG_DIR = os.path.dirname(__file__)
sys.path.append(PKG_DIR)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文