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/
You are not importing views
from page actually, you want to import the HomePageView from your views.
Change your code to this:
# pages/urls.py
from django.urls import path
from .views import homePageView
urlpatterns = [
path('', views.homePageView, name='home')
]
Are you sure that __init__.py
file is present in pages app? If this file is not present in the pages folder, then any file will not be considered as a module.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.