django 学习-5 模板使用流程
首先在模板下建一个index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<h1> hello {{uname}}</h1>
</body>
</html>
</body>
</html>
~
1、from django.http import HttpResponse
from django.template import loader, Context 导入要用的东西
def index(req):
t = loader.get_template('index.html')
c = Context({'uname':'ssj'}) 生成一个context对象
return HttpResponse(t.render(c)) 返回相应的字符串
2、、from django.template import Template
def index1(req):
t = Template('<h1>hello {{uname}}</h1>') 直接通过template把里面的模板以字符串的形式提供出来
c = Context({'uname':'ssj'})
return HttpResponse(t.render(c))
3、from django.shortcuts import render_to_response
def index2(req):
return render_to_response('index.html',{'uname':'ssj1'})
这是一个比较快捷的方式,后面花括号里的内容就相当于上面context的内容
- django 自定用户系统 以及 Django Model 定义语法
- Django初探--开发环境搭建(笔记)
- codeforces 616D Longest k-Good Segment
- go基本工程构建<一>
- golang time.time相关
- mongo实现消息队列
- Golang常用正则验证
- django 学习-4 模板标签
- Google Play应用商店的下载路径(转载)
- codeforces 616D Longest k-Good Segment
- Codeforces Educational Codeforces Round 5 D. Longest k-Good Segment 尺取法
- django 学习-3 模板变量
- codeforces 616D Longest k-Good Segment(two pointer)
- 关于Windows 10,你需要注意什么?
- 说一说golang的协程
- mongo ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused
- goke7101系统搭建
- 学习mongo系列(十一)关系
- 学习mongo系列(九)索引,聚合,复制(副本集),分片
- 修改hosts让google跑起来