【发布时间】:2021-02-24 04:09:57
【问题描述】:
我使用 HTML 创建了一个索引页面,并为“主页”按钮提供了一个 URL,当单击主页按钮时,页面会从索引页面导航到主页。但是它并没有导航到主页,当点击URL地址时,地址会正确更改到指定位置,但显示的页面仍然是索引页面。
<div class="top-menu">
<div class="container">
<div class="row">
<div class="col-xs-2">
<div id="fh5co-logo"><a href="{% url 'index' %}">TrainedbySamson<span>.</span></a></div>
</div>
<div class="col-xs-10 text-right menu-1">
<ul>
<li class="active"><a href="{% url 'tbs_home:home' %}">Home</a></li>
<li><a href="{% static 'gallery.html' %}">Gallery</a></li>
<li><a href="{% static 'about.html' %}">Trainer</a></li>
<li><a href="{% static 'pricing.html' %}">Pricing</a></li>
<li class="has-dropdown">
<a href="{% static 'blog.html' %}">Blog</a>
tbs_home/urls.py:
urlpatterns = [
path('home',views.home, name='home'),
]
tbs_home/views.py:
def home(request):
return render(request, 'home.html')
模板/home.html:
{% load static %}
{% block content%}
<h1 style = "font-family:Georgia;font:40px;font-style:normal;">Hi! {{name}}</h1>
<form action="add" method="POST">
{% csrf_token %}
Enter 1st num : <input type="text" name="num1"><br>
Enter 2nd num : <input type="text" name="num2"><br>
<input type="submit">
</form>
{% endblock %}
所以当我根据代码点击主页按钮时,页面应该导航到 home.html 页面?但它保留在同一个索引页面中,在此先感谢。
【问题讨论】:
-
当我更改它时,我收到错误消息“django.urls.exceptions.NoReverseMatch: Reverse for 'home' not found.'home' 不是有效的视图函数或模式名称。”当我运行服务器时