Issue
I am new to Python and Django, I have an app directory called calc
and inside it there are two files:
views.py
urls.py
In urls.py
, if I type in import views
the server generates an error, however if I type from . import views
everything works fine. Could someone explain why? I thought since the two py files are in the same directly, the import statement should match the views.py
Solution
The answer is really simple. By default if you import everything
, you are importing it from standard pythonish library. If you expand it to from everything.something import anything
it checks the path starting with app everything
modules. If not successful, it also tries to look for global.
In your case it looks inside same folder (starting .
) for module views
which isn't global package, so it cannot be achieved by simple import views
.
Answered By - NixonSparrow
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.