I ran into such a problem, the blocks do not want to be displayed on the page, which I do not really understand, since I did not work with the template engine before. this is code 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')
This is code of index.html
<td>{% block sale %} {% endblock %}</td>
This is code of 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 %}
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>
And this is the construction of the template
This is code of 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'),
]
CodePudding user response:
def sale(request):
return render(request, 'sale.html')
since sale.html
file is outside of the folder Homepage, you should remove the Homepage prefix from the template name.
You should also make sure the URL you're trying to reach calls the sale view.
CodePudding user response:
You need an URL that calls the sale view.
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'),
]