开发者

Making import statements explicit

开发者 https://www.devze.com 2023-03-31 11:20 出处:网络
I was running an app on django\'s local server, and I was able to use import statements without using the project\'s directory:

I was running an app on django's local server, and I was able to use import statements without using the project's directory:

from userprofile.views import Profile

However, now that I've transferred it to an apache server, it is throwing an error if I use the above import, and will only work if I include the full path from the project:

from myproject.userprofile.views import Profile

What is the reason for this differenc开发者_Go百科e, and why is this required? Thank you.


import looks in every directory in sys.path for the specified module (userprofile/__init__.py in your case).

If you compare the values of sys.path on the two systems, you'll see it is missing the myproject directory. You can simply add it to the sys.path list.

0

精彩评论

暂无评论...
验证码 换一张
取 消