我在跟随newboston的django(1.9)教程时面临一个问题,这可能看似重复,但我已经尝试了所有场景来消除这个bug但是失败了。
所以在这里,
我在music
项目中有一个名为djangoLearn
的应用,但在运行此应用程序时,django会出现此错误。它不会读取除admin url模式之外的任何其他url模式。
Using the URLconf defined in djangoLearn.urls, Django tried these URL patterns, in this order:
^admin/
The current URL, music/, didn't match any of these.
from django.conf.urls import url,include
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^music/', include('music.urls')),
]
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$',views.index,name='index')
]
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
def index(request):
return HttpResponse('<h2>Music section</h2>')
我还在settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'music',
]
我正在使用python 2.7
答案 0 :(得分:1)
我也尝试过你的代码,它对我来说很好,我希望你能解决这些可能的错误。
music
app位于您的项目djangoLearn
server's
端口号是否正确setting.py
文件中查看ROOT_URLCONF = 'djangoLearn.urls'
server
; - )如果处理了所有这些可能的错误,请尝试这些
<强> djangoLearn \ urls.py 强>
from django.conf.urls import url,include
from django.contrib import admin
from music.views import index as music_index
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^music/', music_index),
]