[英]Django,page not found 404
當我開始開發服務器時
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/
然后
Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:
^admin/
^blog/
The empty path didn't match any of these.
mysite.urls.py
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^blog/', include('blog.urls')),
]
博客/urls.py
pp_name = 'blog'
urlpatterns = [
# post views
url(r'^$', views.post_list, name='post_list'),
url(r'^(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/'\
r'(?P<post>[-\w]+)/$',
views.post_detail,
name='post_detail'),
]
我懷疑我的模板有問題這是樹所提供的
tree mysite
mysite
├── blog
│ ├── admin.py
│ ├── apps.py
│ ├── __init__.py
│ ├── migrations
│ │ ├── 0001_initial.py
│ │ ├── __init__.py
│ │ └── __pycache__
│ │ ├── 0001_initial.cpython-36.pyc
│ │ └── __init__.cpython-36.pyc
│ ├── models.py
│ ├── __pycache__
│ │ ├── admin.cpython-36.pyc
│ │ ├── __init__.cpython-36.pyc
│ │ ├── models.cpython-36.pyc
│ │ ├── urls.cpython-36.pyc
│ │ └── views.cpython-36.pyc
│ ├── templates
│ │ └── blog
│ │ ├── base.html
│ │ └── post
│ │ ├── detail.html
│ │ └── list.html
│ ├── tests.py
│ ├── urls.py
│ └── views.py
├── db.sqlite3
├── manage.py
└── mysite
├── __init__.py
├── __pycache__
│ ├── __init__.cpython-36.pyc
│ ├── settings.cpython-36.pyc
│ ├── urls.cpython-36.pyc
│ └── wsgi.cpython-36.pyc
├── settings.py
├── urls.py
└── wsgi.py
您的網址與主網址中的/
路徑不匹配。 向url regex r'^$'
添加一些視圖,然后它將起作用。 例如,以名為home
的視圖為例。 請進口相關進口。
from . import views
urlpatterns = [
url(r'^$', views.home, name='home'),
url(r'^admin/', admin.site.urls),
url(r'^blog/', include('blog.urls')),
]
或者你可以喜歡
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^', include('blog.urls')),
]
要使用根站點路徑,應將urlpatterns更改為此:
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^', include('blog.urls')),
]
否則,您仍然可以通過http://127.0.0.1:8000/blog
url獲得視圖。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.