Making import statements explicit
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.
精彩评论