我无法弄清楚为什么我一直得到ModuleNotFoundError:没有名为' HomePage'错误我对Django很新,但是大部分时间都在努力弄清楚如何创建一个主页,我可以链接一个Homepage.html并在我的原始页面上有一个不同的页面。任何帮助将不胜感激这是我在这里的第二个问题请温柔。
这是我的mysite/urls.py
from django.conf.urls import url, include
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^', include('music.urls')),
url(r'^blog/', include('blog.urls')),
url(r'^HomePage/',include('HomePage.urls')),
]
这是我在mysite目录的settings.py中安装的应用程序。 #应用程序定义
INSTALLED_APPS = [
'music',
'blog',
'homepage',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
这是urls.py
music/urls.py
from django.conf.urls import url, include
from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^contact/$', views.contact, name='contact'),
url(r'^HomePage/$', views.HomePage, name='HomePage'),
]
这是views.py music/views.py
from django.shortcuts import render
def index(request):
return render(request, 'music/home.html')
def contact(request):
return render(request, 'music/basic.html', {'content':['If you would like to contact me, please email me','@gmail.com']})
def HomePage(request):
return render(request, 'HomePage/homepage.html')
这是我的文件夹结构。
|-.git
| |-hooks
| |-info
| |-logs
| | |-refs
| | | |-heads
| | | |-remotes
| | | | |-origin
| |-objects
| | |-66
| | |-a9
| | |-aa
| | |-e2
| | |-e5
| | |-info
| | |-pack
| |-refs
| | |-heads
| | |-remotes
| | | |-origin
| | |-tags
|-.idea
| |-libraries
|-__pycache__
|-db
|-DGLIB
| |-mysite
| | |-blog
| | | |-__pycache__
| | | |-migrations
| | | | |-__pycache__
| | | |-templates
| | | | |-blog
| | |-homepage
| | | |-__pycache__
| | | |-migrations
| | |-music
| | | |-__pycache__
| | | |-migrations
| | | | |-__pycache__
| | | |-static
| | | | |-music
| | | | | |-css
| | | | | |-fonts
| | | | | |-img
| | | | | |-js
| | | |-templates
| | | | |-music
| | | | | |-img
| | | | | |-includes
| | |-mysite
| | | |-__pycache__
|-model
| |-__pycache__
|-notebooks
| |-.ipynb_checkpoints
答案 0 :(得分:1)
更改此行:
url(r'^HomePage/',include('homepage.urls')),
到
NSNumber
在您的urls.py文件中,因为您的“主页”作为INSTALLED_APPS中列出的应用而不是“主页”