Reputation: 1
I finally had to post this here after, embarrassingly, being stuck for almost 2 days. I have been trying to import a file from a directory on same level as my parent directory. Here is my project structure:
website
├──pages
│ └──views.py
└──website
└──urls.py
You can see a more detailed structure from the image attached. I am trying to import views.py in urls.py with: from website.pages import views
This gives the error: ModuleNotFoundError: No module named 'website.pages'. I tried using relative import as well: from ..pages import views I got an error here as well: ImportError: attempted relative import beyond top-level package
Please help!
After renaming
Upvotes: 0
Views: 2176
Reputation: 542
As i can see from your pic . You seems to have your project name as website and also your app name as website. Django firstly tries to find the module in your project and not in your app. To correct this you have to import using:
from pages import views
But still that is a bad practice to name your project and your app the same name. Plz change your top level directory name.
Upvotes: 0
Reputation: 1249
This is because the name 'website' of your repository is the same as the name you call.
To solve the problem:
Upvotes: 3