from django.shortcuts import render
from django.http import HttpResponse
from . import models
def index(request):
articles = models.Article.objects.all()
return render(request, 'index.html', {'articles' : articles})
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>主界面</title>
</head>
<body>
<h1>
<a href="{% url 'blog:edit_page' 0 %}">新文章</a>
</h1>
{% for article in articles %}
<a href="{% url 'blog:article_page' article.id %}">{{ article.title}}</a>
<br/>
{% endfor %}
</body>
</html>