【Django】django模板与前端技术(html模板)
创始人
2024-11-21 14:34:24
0

文章目录

    • “python包html”还是“html包python”?
    • 1.新建模板
    • 2.模板语法
    • 3.views.py
    • 测试

“python包html”还是“html包python”?

在前端页面中html代码比python多得多,所以一定是html包python最优!于是引出今天的模板。

大体分为三个步骤:

  1. 新建templates文件夹,写html模板;
  2. 模板语法> 变量语法:{{变量}};代码块语法:{%for%}、{%end for%}
  3. 在views.py中,使用render.hmtl返回。

1.新建模板

  • app目录下新建文件夹“templates”
  • 新建show_excle.html
    在这里插入图片描述
  • 选择语言
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    快速生成html骨架模板
    在这里插入图片描述
    格式化代码方法:
    在这里插入图片描述

2.模板语法

          {% for idx, row in df.iterrows %}                  {% endfor %}             
学号 姓名 语文 数学 英语
{{row.学号}} {{row.姓名}} {{row.语文}} {{row.数学}} {{row.英语}}

在这里插入图片描述

3.views.py

from django.shortcuts import render from django.http import HttpResponse from antproject.settings import BASE_DIR import pandas as pd  # Create your views here. def hello(request):     return HttpResponse("this is hello/")  def show_excel(request):     df=pd.read_excel(BASE_DIR / "data/score.xlsx")     return render(request,"show_excel.html",{"df":df}) 

在这里插入图片描述

测试

在这里插入图片描述

相关内容

热门资讯

透视苹果版"hhpo... 透视苹果版"hhpoker脚本"详细辅助我来教教你(真是是真的有挂);1、起透看视 hhpoker脚...
透视脚本!wepoker透视脚... 透视脚本!wepoker透视脚本网页(透视)永久脚本辅助挂(详细辅助详细教程);wepoker透视脚...
透视新版"wepok... 透视新版"wepoker辅助器免费"详细辅助可靠技巧(一贯真的有挂)1、wepoker辅助器免费系统...
透视app!智星菠萝辅助(透视... 透视app!智星菠萝辅助(透视)永久脚本辅助app(详细辅助必备教程)1、智星菠萝辅助透视辅助简单,...
透视免费"hhpok... 透视免费"hhpoker开挂教程"详细辅助玩家教程(确实是真的有挂)运hhpoker开挂教程辅助工具...
透视工具!佛手大菠萝辅助(透视... 透视工具!佛手大菠萝辅助(透视)永久脚本辅助挂(详细辅助新2025教程);1、玩家可以在佛手大菠萝辅...
透视线上"wepok... 透视线上"wepoker私局辅助"详细辅助2025版教程(果然存在有挂);1、wepoker私局辅助...
透视黑科技!wepoker开脚... 透视黑科技!wepoker开脚本视频(透视)永久脚本辅助助手(详细辅助第三方教程);1、这是跨平台的...
透视游戏"wepok... 透视游戏"wepokerplus脚本"详细辅助分享教程(竟然有挂)透视游戏"wepokerplus脚...
透视模拟器!wepoker私人... 透视模拟器!wepoker私人局透视插件(透视)永久脚本辅助器(详细辅助介绍教程)1、wepoker...