Django入门与实践-第6章:第一个视图函数

boards/views.py

1
2
3
4
5
6
7
8
9
10
11
12
13
from django.http import HttpResponse
from .models import Board

def home(request):
boards = Board.objects.all()
boards_names = list()

for board in boards:
boards_names.append(board.name)

response_html = '<br>'.join(boards_names)

return HttpResponse(response_html)

结果就是这个简单的HTML页面:

6

Powered by Hexo and Hexo-theme-hiker

Copyright © 2013 - 2021 朝着牛逼的道路一路狂奔 All Rights Reserved.

访客数 : | 访问量 :