Reputation: 463
I'm new to Django and am trying to create a very simple app off of a tutorial I found online.
Working on a mac
Django Version 2.0.7
Python 3.7.0
My file structure:
helloworld
......venv
..........(other files)
......helloworld_project
..........(other files)
......manage.py
......pages
.........._ pycache _
..............otherfiles
..........admin.py
..........apps.py
..........migrations
..............(other files)
..........models.py
..........tests.py
..........urls.py
..........views.py
The problem: when I run my urls.py file, I get the following message:
Traceback (most recent call last):
File "/Users/Bethany/Desktop/helloworld/pages/urls.py",
line 3, in <module>
from pages import views
ModuleNotFoundError: No module named 'pages'
My urls.py file:
# pages/urls.py
from django.urls import path
from pages import views
urlpatterns = [
path('', views.homePageView, name='home')
]
I've tried replacing "from pages import views" with "from . import views" and get the same message.
I've looked through a few similar questions on stack overflow, but haven't had success with finding a solution to fix my issue. does anyone have any suggestions?
Thanks!
If needed, this is the tutorial I'm following: https://djangoforbeginners.com/hello-world/
Upvotes: 3
Views: 7856
Reputation: 103
The exact same thing happened with me today, turns out i was missing the comma after 'pages.apps.PageConfig'. Super silly mistake
Upvotes: 2
Reputation: 761
I had the same problem minutes ago, but the only issue which caused this same problem for me was a typo in configuring my app in the settings.py instead of 'pages.apps.PagesConfig' i wrote 'pages.apps.pagesconfig' and then the problem was solved frequently quickly.
Upvotes: 0
Reputation: 4035
since the urls.py
and and views.py
in the same directory therefor you can simply do from . import views
it will import all the views.
Upvotes: 0
Reputation: 1
Since the urls file is already in the app pages you can't import it using the said name. I would suggest you change from pages import views
to from . import views
Upvotes: 0