你快到了。试试这个:
views.py
from news.models import News
from django.shortcuts import render
def HomePageView(request):
context = {}
news = News.objects.order_by('-date')[:3]
context['news']=news
return render(request,'home.html',context)
home.html
{% extends 'base.html' %}
{% block title %}Home{% endblock title %}
{% block content %}
<div class="jumbotron">
<h1 class="display-4">Lakeland Cycle Club</h1>
<p class="lead">The home of cycling in Fermanagh.</p>
<p class="lead">
<a class="btn btn-primary btn-lg" href="{% url 'news_list' %}" role="button">View All Club News</a>
</p>
<span class="font-weight-bold">
{%for new in news%}
{{new.title}}
{%endfor%}
</span>
</div>
{% endblock content %}