Django 路径错误 - 没有名为 models 的模块
我在 Django 应用程序中遇到导入错误,我想这很简单,但我无法弄清楚......
这是一个简单的记事本应用程序,称为“notes”,有 2 个模型,“note”和“notes”。 “类别”。为了清理一切,我想将每个模型视图和视图分开。 url,所以这是我得到的:
/笔记
admin.py
forms.py
models.py
/url
category.py
note.py
/视图
category.py
note.py
问题
是我的视图找不到模型,这里是回溯 - http:// dpaste.com/hold/539425/ 和部分代码:http://dpaste.com/ hold/539416/
我没有在上面的代码片段中提到 _init_.py 文件,但我仔细检查了所有这些文件......
I have an import error in a Django app, I guess it's pretty simple but I can't figure it out…
It's a simple notepad app, called «notes» with 2 models, «note» & «category». To clean things up, I wanted to seperate each models views & urls, so here is what I get:
/notes
admin.py
forms.py
models.py
/urls
category.py
note.py
/views
category.py
note.py
The problem is that my views don't find the models, here is the Traceback - http://dpaste.com/hold/539425/ and parts of the code: http://dpaste.com/hold/539416/
I didn't mention the _init_.py files in the above snippet, but I double-checked all of them…
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的代码粘贴显示
fromnotes.models import Category, Note
但您的回溯显示from models import Category, Note
。很难判断它们是否是同一行,因为您只是粘贴片段。不过,它应该始终是“from Notes.models import foo”。您确定始终在
models
导入中引用notes
应用吗?更新:
如果您使用正确的
from foo.models import bar
语法,那么我的下一个想法是您可能存在循环依赖关系,阻止 Python 从模型文件导入内容。但回溯意味着找不到notes/models.py。所以...当您说您仔细检查了 init.py 文件时,并不意味着它们是正确的。 :p 在notes/ 和notes/urls/ 中应该有一个——它们不必包含任何内容。
Your code pastie says
from notes.models import Category, Note
but your traceback saysfrom models import Category, Note
. It's hard to tell if those are the same line because you're only pasting snippets. Still, it should be 'from notes.models import foo' always.Are you sure you're always referencing the
notes
app in yourmodels
import?UPDATE:
If you're using the correct
from foo.models import bar
syntax, then my next thoughts are that you've possibly got a circular dependency that's stopping Python importing things from the models file.But the traceback implies the notes/models.py can't be found. So... when you say you double-checked the init.py files, that doesn't mean they're right. :p There should be one in notes/ and also in notes/urls/ -- they don't have to contain anything.
应该是
It should be