zoukankan      html  css  js  c++  java
  • 模板变量

    1. url配置

    urlpatterns = [
        re_path(r'temp_test/',temp_test)
    ]
    

    2. views配置

    def temp_test(request):
        name = "kyle"
        temp_list = [1,2,3,4]
        class Person(object):
            def __init__(self,name):
                self.name = name
    
            def eat(self):
                return "food"
        person_yuan = Person("yuan")
        person_tang = Person("tang")
        person_chan = Person("chan")
    
    
        person_list = [person_chan,person_yuan,person_tang]
        return render(request, "temp_test.html", {"name":name,
                                                  "temp_list":temp_list,
                                                  "person_list":person_list
                                                  })
    

    3. html获取变量

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
    <p> {{ name }},别玩手机了</p>
    <p> {{ temp_list.1 }}</p>
    <hr>
    
    <p> {{ person_list.1.name }}</p>
    <p> {{ person_list.1.eat }}</p>
    </body>
    </html>
    

    4. 页面测试

  • 相关阅读:
    java线程
    windows Server 安装
    nginx正则反向代理
    crontab定时任务启动脚本失败
    数据结构
    异常概念
    shell日期遍历复制文件
    多态和抽象
    图1 列出连通集
    PTA 代码注意事项
  • 原文地址:https://www.cnblogs.com/NGU-PX/p/14189580.html
Copyright © 2011-2022 走看看