Django入门指南-第7章:模板引擎设置(完结)
2024-09-21 21:13:16
<!--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>
最新文章
- 【CityHunter】游戏流程设计及技术要点
- Nodejs创建客户端
- gitlab 配置
- C#4.0新特性:可选参数,命名参数,Dynamic
- .NET架构师技能体系
- 基于Android Studio搭建hello world工程
- Git教程--Git安装和版本库的创建
- 测试通用的InsertOrUpdate
- C++ pair 使用方法
- Justinmind教程(3)——管理原型
- MySQL创建用户与授权方法
- datatable使用笔记
- java中的IO 的示例
- java.exe和javaw.exe的区别
- 【三分】light bulb(zoj3203)
- C#快速删除bin和obj文件夹的方法
- King&#39;s Quest POJ - 1904(强连通分量)
- HtmlImageGenerator字体乱码问题解决、html2image放linux上乱码问题解决
- Server Process
- Linux中find
热门文章
- Linux批量查询替换字符串
- linux c++下载http文件并显示进度<;转>;
- python判断unicode是否是汉字,数字,英文,或者其他字符
- node系列:全局与本地
- urllib 和urllib2 模块使用简例
- Access denied for user &#39;root&#39;@&#39;localhost&#39; (using password:YES)解决方法
- python中的__name__==&#39;__main__&#39;如何简单理解(一)
- java swing:文本框添加滚动条
- poj1417(带权并查集+背包DP+路径回溯)
- 第五章&#160;二叉树(d)二叉树实现