我遇到了這樣的問題,塊不想顯示在頁面上,我不太明白,因為我之前沒有使用過模板引擎。這是代碼views.py
class IndexView(generic.ListView):
template_name = 'Homepage/index.html'
model = Goods
context_object_name = 'goods'
def sale(request):
return render(request, 'Homepage/sale.html')
這是 index.html 的代碼
<td>{% block sale %} {% endblock %}</td>
這是sale.html的代碼
{% extends "index.html" %}
{% block sale %}
<td class ="sale">
<img src="image">
<h1 class="description">description</h1>
<a class="buy" href="#openModal" >
<span >Купить</span></a>
<h1 class="price">цена</h1>
</td>
{% endblock %}
這是模板的構建

這是 urls.py 的代碼
from django.urls import path
from django.conf.urls import include, url
from . import views
app_name = 'Homepage'
urlpatterns = [
path('', views.IndexView.as_view(), name='index'),
path('<int:pk>/', views.DetailView.as_view(), name='detail'),
path('<int:pk>/results/', views.ResultsView.as_view(), name='results'),
path('<int:question_id>/vote/', views.vote, name='vote'),
path('', views.HomeView.as_view(), name='home'),
]
uj5u.com熱心網友回復:
def sale(request):
return render(request, 'sale.html')
由于sale.html檔案位于檔案夾 Homepage 之外,您應該從模板名稱中洗掉 Homepage 前綴。您還應該確保您嘗試訪問的 URL 呼叫了銷售視圖。
uj5u.com熱心網友回復:
您需要一個呼叫銷售視圖的 URL。
urlpatterns = [
path('', views.IndexView.as_view(), name='index'),
path('<int:pk>/', views.DetailView.as_view(), name='detail'),
path('<int:pk>/results/', views.ResultsView.as_view(), name='results'),
path('<int:question_id>/vote/', views.vote, name='vote'),
path('', views.HomeView.as_view(), name='home'),
path('sale', views.sale, name='sale'),
]
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/355224.html
下一篇:嘗試在Django中搜索ManyToMany欄位時出現“RelatedFieldgotinvalidlookup:contains”
