開発サーバーを起動すると
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')),
]
blog / 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/
がメインURLのパスと一致しません。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')),
]
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加