简体   繁体   中英

django 404 not found page

I am trying to show a blogpost on the site.

Below is details of urls and view file details but still it showing a 404 not found page

urls.py

from django.urls import path
from . import views

urlpatterns = [
    path("", views.index, name="ShopHome"),
    path("blogpost/", views.blogpost, name="blogpost")
]

views.py

from django.shortcuts import render

# Create your views here.
from django.http import HttpResponse

def index(request):
    return render(request, 'blog/index.html')

def blogpost(request):
    return render(request, 'blog/blogpost.html')

Showing:

404 not found page

you should include urls.py of your application to project urls.py

actually if your project name is " mysite " and your application name is " blogspot ", you should include mysite/blogspot/urls.py on this file mysite/mysite/urls.py like this:

from django.urls import path, include

urlpatterns = [
   path('', include('blogspot.urls')),
]

实际上,我忘记在URL中注册此应用程序的URL时添加斜杠

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM