主要功能是渲染模板,看官例:

 

from django.views.generic.base import TemplateView
from articles.models import Article
class HomePageView(TemplateView):
template_name = "home.html"
def get_context_data(self, **kwargs):
context = super(HomePageView, self).get_context_data(**kwargs)
context['latest_articles'] = Article.objects.all()[:5]
return context
Views.py

相关文章:

  • 2022-12-23
  • 2021-08-30
  • 2022-01-29
  • 2021-06-24
  • 2021-08-17
  • 2021-10-22
  • 2021-11-29
猜你喜欢
  • 2021-09-10
  • 2021-09-02
  • 2021-12-05
  • 2021-09-13
  • 2022-12-23
  • 2021-07-03
  • 2021-08-24
相关资源
相似解决方案