django-模板之模板变量二

将views中的变量传递给html界面

book/views.py

from django.views import View
from django.shortcuts  render

# Create your views here.
class IndexView(View):
    def get(self,request):
        requests={
            'title':"python web",book_list':{
                book_name1javabook_name2pythonreturn render(request,index.html",context=requests)

index.html

<!DOCTYPE html>
<html lang=en">
<head>
    <meta charset=UTF-8">
    <title>{{title}}</title>
    <style>
        .header {
            height: 200px;
            background-color: fuchsia;;
        }
    </style>
</head>
<body>
    <div class=header">
        <h1>{{book_list.book_name1}}</h1>
        <h1>{{book_list.book_name2}}</h1>
    </div>
</body>
</html>

 

 第二种方式:

 

 

 

 

相关文章

注:所有源代码均实测运行过。所有源代码均已上传CSDN,请有...
继承APIView和ViewSetMixin;作用也与APIView基本类似,提供...
一、Django介绍Python下有许多款不同的 Web 框架。Django是重...
本文从nginx快速掌握到使用,gunicorn快速掌握到使用,实现小...
uniapp微信小程序订阅消息发送服务通知
Django终端打印SQL语句 1 Setting配置: 2 默认python 使用的...