修改settings的DIRS路径,即模板文件查找路径
编写view脚本,增加视图函数test_html
from django.shortcuts import render #导入reder方法
def test_html(request):
return render(request,'test.html',{'name':'c语言中文网'})#根据字典数据生成动态模板
renbder 方法的作用是结合一个给定的模板和一个给定的字典,并返回一个渲染后的 HttpResponse 对象。通俗的讲就是把字典格式的内容, 加载进 templates 目录中定义的 HTML 文件, 最终通过浏览器渲染呈现.
rebder() 方法的完整参数格式如下所示:
render(request, template_name, context=None, content_type=None, status=None, using=None)
添加html文件
<p style="font-size:50px;color:red">{{name}},网址是<a href="http://c.biancheng.net/">http://c.biancheng.net/</a></p>
添加url