<!--templates/home.html-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Boards</title>
</head> <body>
<h1>Boards</h1>
{% for board in boards %}
{{ board.name }} <br>
{% endfor %}
</body>
</html>
TEMPLATES = [
{
'DIRS': [os.path.join(BASE_DIR, 'templates')],
},
] #我们可以使用Python shell进行调试:
  python manage.py shell
  from django.conf import settings
  settings.BASE_DIR
  import os
  os.path.join(settings.BASE_DIR, 'templates')
# boards/views.py
from django.shortcuts import render
from .models import Board def home(request):
boards = Board.objects.all()
return render(request, 'home.html', {'boards': boards}) <!--我们可以用一个更漂亮的表格来替换,改进HTML模板:-->
<!--templates/home.html-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Boards</title>
</head> <body>
<h1>Boards</h1>
<table border="1">
<thead>
<tr>
<th>Board</th>
<th>Posts</th>
<th>Topics</th>
<th>Last Post</th>
</tr>
</thead>
<tbody>
{% for board in boards %}
<tr>
<td>{{ board.name }}<br>
                <small style="color: #888">{{ board.description }}</small>
              </td>
<td>0</td>
<td>0</td>
<td></td>
</tr>
{% endfor %}
</tbody>
</table>
</body>
</html>

最新文章

  1. 【CityHunter】游戏流程设计及技术要点
  2. Nodejs创建客户端
  3. gitlab 配置
  4. C#4.0新特性:可选参数,命名参数,Dynamic
  5. .NET架构师技能体系
  6. 基于Android Studio搭建hello world工程
  7. Git教程--Git安装和版本库的创建
  8. 测试通用的InsertOrUpdate
  9. C++ pair 使用方法
  10. Justinmind教程(3)——管理原型
  11. MySQL创建用户与授权方法
  12. datatable使用笔记
  13. java中的IO 的示例
  14. java.exe和javaw.exe的区别
  15. 【三分】light bulb(zoj3203)
  16. C#快速删除bin和obj文件夹的方法
  17. King&#39;s Quest POJ - 1904(强连通分量)
  18. HtmlImageGenerator字体乱码问题解决、html2image放linux上乱码问题解决
  19. Server Process
  20. Linux中find

热门文章

  1. Linux批量查询替换字符串
  2. linux c++下载http文件并显示进度&lt;转&gt;
  3. python判断unicode是否是汉字,数字,英文,或者其他字符
  4. node系列:全局与本地
  5. urllib 和urllib2 模块使用简例
  6. Access denied for user &#39;root&#39;@&#39;localhost&#39; (using password:YES)解决方法
  7. python中的__name__==&#39;__main__&#39;如何简单理解(一)
  8. java swing:文本框添加滚动条
  9. poj1417(带权并查集+背包DP+路径回溯)
  10. 第五章&#160;二叉树(d)二叉树实现