1
2
3
4
5
6
7
8
9
10
11
12
13
from django.shortcuts import render
from .models import Topic # 引入编写的模型

def index(request):
"""学习笔记的主页"""
return render(request, 'learning_logs/index.html')

def topics(request):
"""显示所有的主题"""
topics = Topic.objects.order_by('data_added')
context = {'topics': topics} # 上下文: 模板中通过模板语言使用的python变量的字典
return render(request, 'learning_logs/topics.html', context) # 载入模板,填充上下文,再返回由它生成的 HttpResponse 对象
# HttpResponse 对象: 返回给浏览器的对象