2017-05-14 54 views
0

我的代碼Python的Django的網站開發

網站/ 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

錯誤仍不符合你的代碼。確保清除任何'.pyc'文件並重新啓動服務器。 – knbk

回答

0

你在你的music/urls.py有錯字,應該是:

from django.conf.urls import url 

from . import views 

urlpatterns = [ 

    url(r'^$', views.index, name='index'), 

] 
-1

在網站/ 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')), 
] 
+0

你不應該使用'$'和'include()'。 – knbk

+0

[@knbk](http://stackoverflow.com/users/2615075/knbk):我用樣本django項目重現了上述錯誤。我已清除我的.pyc文件。儘管如此,我仍然在上面得到同樣的錯誤讓我明確如何正確解決。 –