【发布时间】:2021-03-05 10:25:57
【问题描述】:
当我尝试打开另一个视图时,我需要有关 {% url (url to template) %} 的帮助,但我看到了 NoRewerseMatch 错误。
这是我的 html 文件:
{% load static %}
<head>
<link href='{% static "navbar_style.css" %}' rel="stylesheet", type="text/css">
</head>
<header>
<nav class="headlist">
---> <a href='{% url "home" %}'><img id = "img1" src="{% static 'logo.png' %}" alt="logo"></a>
<ul>
<li><a href="#">O nas</a></li>
<li><a href="#">Kontakt</a></li>
<li><a>Zajęcia</a></li>
</ul>
</nav>
</header>
我的应用(页面)/urls.py
from django.contrib import admin
from django.urls import path
from . import views
app_name = 'pages'
urlpatterns = [
path('', views.home_view, name='home_view'),
path('index/', views.index_view, name='index_view'),
]
views.py
import...
# Create your views here.
def home_view(request):
listoftexts = Text.objects.order_by('-pub_date')
context = {
'listoftexts': listoftexts
}
return render(request, 'pages/home.html', context)
def index_view(request):
listoftexts = Text.objects.order_by('-pub_date')
context = {
'listoftexts': listoftexts
}
return render(request, 'pages/index.html', context)
【问题讨论】:
标签: python html django url django-urls