我查看我的文件超过50次,我感到沮丧。 这是我得到的错误:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/
Using the URLconf defined in project1.urls, Django tried these URL patterns, in this order:
^admin/
^music/
The current URL, , didn't match any of these.
You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.
这是我在project1文件夹中的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 views
urlpatterns = [
url(r'^$', views.index, name='index'),
]
这是我在settings.py中安装的应用程序,无论出于何种原因:
INSTALLED_APPS = [
'music.apps.MusicConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
请帮助,谢谢!
答案 0 :(得分:2)
详细了解Django告诉您的内容,为什么找不到您的请求网址的相应页面:
使用project1.urls中定义的URLconf,Django尝试了这些URL 模式,按此顺序:
^admin/ ^music/
当前网址与其中任何一个都不匹配。
它基本上只有两个视图,可以处理您的请求,只能通过127.0.0.1:8000/admin/
和127.0.0.1:8000/admin/
访问。您正试图访问/
的内容,而这些内容并不存在。
解决方案是在URL 127.0.0.1:8000
处添加另一个视图作为根页面或索引页面,或者更改两个现有urlpatterns之一的URL以匹配根。
以下示例将新视图index
添加到您应用的根目录:
urlpatterns = [
url(r'^$', index), # this is important and matches "/"
url(r'^help/', include('apps.help.urls')),
url(r'^credit/', include(extra_patterns)),
]
答案 1 :(得分:1)
尝试下面的网址
http://127.0.0.1:8000/music/
或从网址格式中删除music
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^', include('music.urls')),
]