【发布时间】:2021-11-03 11:36:05
【问题描述】:
我还没有设法找到它给出错误的原因? 在 StackOverflow 中复制粘贴以获得 exp 的地方收到了很多答案
所以情况是我的 navbar.html 中的 URL 返回错误 404 找不到 x.html
这里是每个 py 文件的代码:
views.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')
setting.py:
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, '../blog_level/static')
STATICFILES_DIRS= [
os.path.join(BASE_DIR, 'static'),
]
navbar.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'),
]
fist_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')),
]
请找出调试错误:
我还是不明白这个过程的错误为什么它不会链接到正确的页面,自然是基于以下专家在一个简单的项目级别。
【问题讨论】:
-
你应该访问
/experience/,而不是Experience.html。
标签: python html django-views django-templates