python - URL 错误 404 找不到 Django 页面错误 x.html
问题描述
我还没有设法找到为什么它会给出错误?在 StackOverflow 中复制粘贴以获得 exp 的地方收到了很多答案
所以情况是我的 navbar.html 中的 URL 返回错误 404 找不到 x.html
这是每个 py 文件的代码:
视图.py:
from django.shortcuts import render, redirect
from django.core.mail import send_mail, BadHeaderError
from django.http import HttpResponse, HttpResponseRedirect
from django.conf import settings
from .forms import ContactForm
# Create your views here.
def home_page(request):
return render(request, 'index.html')
def education(request):
return render(request, 'Education.html')
def experience(request):
return render(request, 'Experience.html')
def portfolio(request):
return render(request, 'Portfolio.html')
设置.py:
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, '../blog_level/static')
STATICFILES_DIRS= [
os.path.join(BASE_DIR, 'static'),
]
导航栏.html:
<ul class="u-align-center u-nav u-popupmenu-items u-unstyled u-nav-2"><li class="u-nav-item"><a class="u-button-style u-nav-link" href="{% url 'homepage' %}" style="padding: 10px 0px; text-shadow: 0 0 8px rgba(128,128,128,1);">Home</a>
</li><li class="u-nav-item"><a class="u-button-style u-nav-link" href="{% url 'experience' %}" style="padding: 10px 0px; text-shadow: 0 0 8px rgba(128,128,128,1);">Experience</a>
</li><li class="u-nav-item"><a class="u-button-style u-nav-link" href="{% url 'education' %}" style="padding: 10px 0px; text-shadow: 0 0 8px rgba(128,128,128,1);">Study</a>
</li><li class="u-nav-item"><a class="u-button-style u-nav-link" href="{% url 'portfolio' %}" style="padding: 10px 0px; text-shadow: 0 0 8px rgba(128,128,128,1);">Portfolio</a>
</li><li class="u-nav-item"><a class="u-button-style u-nav-link" href="{% url 'homepage' %}#sec-1120" data-page-id="134427998" style="padding: 10px 0px; text-shadow: 0 0 8px rgba(128,128,128,1);">Contact</a>
</li></ul>
blog_level\urls.py :
from django.contrib import admin
from django.urls import path, re_path
from . import views
urlpatterns = [
path('', views.home_page, name='homepage'),
path('education/', views.education, name='education'),
path('experience/', views.experience, name='experience'),
path('portfolio/', views.portfolio, name='portfolio'),
]
first_website_app_level.py :
"""first_website_app_level URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.2/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('', include('blog_level.urls')),
]
并请找到调试错误:
我仍然不明白为什么它不会链接到正确的页面的过程的错误,自然基于以下专家在一个简单的项目级别。
解决方案
In是在andDjango
urls.py
之间具有映射的文件,因此如果您想访问页面,您必须拥有您的as (代码中没有任何更改,只需更新您在浏览器中使用的 URL),因为映射为views
url
Experience.html
url
127.0.0.1:8000/experience
urls.py
path('experience/', views.experience, name='experience'),
这是一个关于 url 映射如何工作的好文档。
推荐阅读
- r - 使用 tidyverse 根据时间点和标准对数据进行排序
- r - 谁能弄清楚为什么我收到我的代码错误?我已经安装了 tidyverse 和 dplyr 所以我不明白
- firebase - Firebase 云功能未部署
- php - 带引导程序的阵列显示
- typescript - 从键列表创建通用对象
- python - 如何在python中将反向列表返回到其原始状态
- r - 如何对 Month 变量从 1 到 12 进行排序?这在使计数累积时成为一个问题,然后累积的数字变得错误
- google-maps - 是否可以从谷歌地图中获取数据
- python-3.x - 为什么我的代码卡在中间?
- python - 如何让我的机器人判断给出的数字是高于还是低于答案?[不和谐.py]