如果我在目录main.py和somemodule.py有两个python模块,我可以使用import somemodule 。
./ main.py somemodule.py __init__.py
在Django应用程序中,我们有urls.py和views.py ,为什么在这种情况下不会import views工作? 但相对from . import views from . import views作品?
If I have two python modules in a directory main.py and somemodule.py, I can import somemodule by using import somemodule.
./ main.py somemodule.py __init__.py
In django application where we have urls.py and views.py, why won't import views work in this case? But relative import from . import views works?
最满意答案
这是因为python 3的导入风格,与Django无关。
阅读本文以获取更多详细信息: 导入语句python3中的更改
That's because of python 3 import style and is irrelevant to Django.
Read this for more details: Changes in import statement python3
更多推荐
发布评论