[英]Creating a beginners app using Django/Python: ModuleNotFoundError: No module named 'pages'
[英]Following a tutorial using Django/Python: ModuleNotFoundError: No module named 'pages'
我是 Django 的新手,我正在尝试根据我在网上找到的教程创建一个非常简单的应用程序。
在 Mac 上工作 Django 版本 2.0.7 Python 3.7.0
我的文件结构:
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
问题:当我运行我的 urls.py 文件时,我收到以下消息:
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')
]
我尝试用“from.import views”替换“from pages import views”并得到相同的消息。
我已经查看了一些关于堆栈溢出的类似问题,但没有成功找到解决我的问题的解决方案。 有没有人有什么建议?
谢谢!
如果需要,这是我正在关注的教程: https://djangoforbeginners.com/hello-world/
您实际上不是从页面导入views
,而是希望从视图中导入 HomePageView。
将您的代码更改为:
# pages/urls.py
from django.urls import path
from .views import homePageView
urlpatterns = [
path('', views.homePageView, name='home')
]
您确定页面应用程序中存在__init__.py
文件吗? 如果页面文件夹中不存在此文件,则任何文件都不会被视为模块。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.