Django[11]模板Template context和Bootstrap使用

视图views.py中

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26


from __future__ import unicode_literals

from django.shortcuts import render

# Create your views here.
from django.http import HttpResponse

def (request):
context = {
"title""home"
}
return render(request,"index.html",context)

def posts_create(request):
context = {
"title""create"
}
return render(request,"index.html",context)

def posts_detail(request):
context = {
"title""detail"
}
return render(request,"index.html",context)

index.html中

context大专栏  Django[11]模板Template context和Bootstrap使用填充模板 index.html,然后再返回

index.html中添加如下代码:

1
<h1>Hello {{ title }}}</h1>

context是一个字典,存放要渲染到页面的数据

Bootstrap模板使用

1. 下载模板文件

模板文件链接

2. 把html文件拷贝到了templates文件夹下面

3. 新建一个statics文件夹,用于存放css文件和js文件

4. 把css和js文件拷贝到statics文件夹下

5. 在settings.py中配置statics文件夹

1
2
3
4

STATICFILES_DIRS = [
os.path.join(BASE_DIR, "statics")
]

6. 将html文件中指定位置的css和js文件的路径修改为/static/…

文档结构如下:

效果如图:

via Django1.10教程 -11 -模板Template context和Bootstrap使用

猜你喜欢

转载自www.cnblogs.com/liuzhongrong/p/12289604.html