【发布时间】:2020-02-04 01:00:40
【问题描述】:
我对为什么我的 HTML 模板没有显示感到困惑。
我正在尝试学习类基础视图而不是 Django 上的函数。
我知道 URL 可以正常工作,因为 {% extend base.html %} 正在显示,但是像 h1 标记之类的其他任何内容都没有显示在渲染中?
谁能帮帮我。
views.py
from django.shortcuts import render
from django.views import View
from django.views.generic import (
CreateView,
DetailView,
ListView,
UpdateView,
ListView,
DeleteView
)
from .models import Article
class ArticleListView(ListView):
template_name = 'article/article_list.html'
queryset = Article.objects.all()
url.py
from django.contrib import admin
from django.urls import path
from .views import (
ArticleListView
)
app_name = 'article'
urlpatterns = [
path('', ArticleListView.as_view(), name = 'article_list'),
article_list.html
{%extends 'base.html'%}
<h1> Test </h1>
<h1> Test </h1>
{%block content%}
{% for instance in object_list %}
<p>{{instance.id}} - <a href = '{{instance.get_absolute_url}}'> {{instance.title}} </a></p>
{%endfor%}
{%endblock%}
[This is the outcome when i request get html, The current html is coming from base.html][1]
[1]: https://i.stack.imgur.com/W09EE.png
【问题讨论】:
-
您必须将这些
h标签放入您的块中才能渲染和显示它们 -
嗨 beer44,我试过了。除了 base.html 中的 html 之外,它仍然没有渲染任何内容
-
显示你的 base.html 模板。
-
我认为 Django 有问题。从那以后,我删除了所有表并重置了所有内容并进行了迁移。现在它似乎又开始工作了。 >.