我的代码
网站/ urls.py
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^music/', include('music.urls')),
]
音乐/ urls.py
from django.conf.urls import url
from . import index
urlpatterns = [
url('^$', views.index, name='index'),
]
views.py
from django.http import HttpResponse
def index(request):
return HttpResponse ("This is Music Homepage ")
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'music',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'website.urls'
问题
Using the URLconf defined in website.urls, Django tried these URL patterns, in this order:
^admin/
The current path, music, didn't match any of these.
答案 0 :(得分:0)
您的music/urls.py
中有拼写错误,应该是:
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
]
答案 1 :(得分:-1)
在website / urls.py中使用:
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^$', include('music.urls')),
]
而不是:
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^music/', include('music.urls')),
]