Django中的类视图,Html不显示

2024-09-28 22:55:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我不明白为什么我的HTML模板没有出现。你知道吗

我试图学习Django上的类基视图而不是函数。你知道吗

我知道该URL正在工作,因为{%extend基本.html%}但是像h1标签这样的任何东西都没有显示在渲染中?你知道吗

有人能帮忙吗。你知道吗

你知道吗视图.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()

你知道吗网址.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'),

文章_列表.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



Tags: djangoinstancenamefrompyimport视图html