找不到页面 (404) 请求方法:GET 尝试单击另一个 .html 文件
Page not found (404) Request Method: GET trying to click to another .html file
我做了很多研究,我一定很明显错过了一些已经做过的事情或一些错误的事情。我是 运行 的服务器是 localhost:8000
它实际上发生在所有三个 .html 文件上。
我添加了主页,一切正常,直到我尝试单击另一个 html file
并收到。
Screenshot of the error message here Page not found (404) Request Method: GET trying to Using the URLconf defined in user.urls,
Django 按以下顺序尝试了这些 URL 模式:`
admin/
secret/
home/ [name='home']
home/ [name='contact']
home/ [name='Project']
^static/(?P<path>.*)$
index/Project.html.
这是root urls.py
:
from django.contrib import admin
from django.urls import path, include
from django.conf.urls import url
from django.conf import settings
from django.conf.urls.static import static
from django.views.generic import RedirectView
from portfolio_django import views
admin.autodiscover()
urlpatterns = [
path('admin/', include('admin_honeypot.urls', namespace='admin_honeypot')),
url('secret/', admin.site.urls),
path('home/', include("portfolio_django.urls")),
]+ static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
from django.urls import path
from portfolio_django import views
urlpatterns = [
path('', views.home, name='home'),
path('', views.contact, name='contact'),
path('', views.Project, name='Project')
views.py
from django.shortcuts import render
# Create your views here.
def home(request):
return render(request, 'home.html')
def Portfolio(request):
return render(request, 'Project.html')
def contact(request):
return render(request, 'contact.html')
您收到错误 404,因为您还没有为 http://localhost:8000
定义 url 模式
您需要将路径('home/', include("portfolio_django.urls"))
更改为path('', include("portfolio_django.urls"))
并更改以下内容:
path('', views.home, name='home'),
path('contact/', views.contact, name='contact'),
path('project/', views.Project, name='Project')
我做了很多研究,我一定很明显错过了一些已经做过的事情或一些错误的事情。我是 运行 的服务器是 localhost:8000
它实际上发生在所有三个 .html 文件上。
我添加了主页,一切正常,直到我尝试单击另一个 html file
并收到。
Screenshot of the error message here Page not found (404) Request Method: GET trying to Using the URLconf defined in user.urls,
Django 按以下顺序尝试了这些 URL 模式:`
admin/
secret/
home/ [name='home']
home/ [name='contact']
home/ [name='Project']
^static/(?P<path>.*)$
index/Project.html.
这是root urls.py
:
from django.contrib import admin
from django.urls import path, include
from django.conf.urls import url
from django.conf import settings
from django.conf.urls.static import static
from django.views.generic import RedirectView
from portfolio_django import views
admin.autodiscover()
urlpatterns = [
path('admin/', include('admin_honeypot.urls', namespace='admin_honeypot')),
url('secret/', admin.site.urls),
path('home/', include("portfolio_django.urls")),
]+ static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
from django.urls import path
from portfolio_django import views
urlpatterns = [
path('', views.home, name='home'),
path('', views.contact, name='contact'),
path('', views.Project, name='Project')
views.py
from django.shortcuts import render
# Create your views here.
def home(request):
return render(request, 'home.html')
def Portfolio(request):
return render(request, 'Project.html')
def contact(request):
return render(request, 'contact.html')
您收到错误 404,因为您还没有为 http://localhost:8000
定义 url 模式您需要将路径('home/', include("portfolio_django.urls"))
更改为path('', include("portfolio_django.urls"))
并更改以下内容:
path('', views.home, name='home'),
path('contact/', views.contact, name='contact'),
path('project/', views.Project, name='Project')