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 difference, and why is this required? Thank you.
importlooks in every directory insys.pathfor the specified module (userprofile/__init__.pyin your case).If you compare the values of
sys.pathon the two systems, you’ll see it is missing themyprojectdirectory. You can simply add it to thesys.pathlist.