在导入前端模板时,总是要手工处理所有引用,这里写一份代码,解决这个问题:

import redef change_static(script_origin: str):script_origin = script_origin.split('\n')for script_origin in script_origin:script_origin = script_origin.strip()if script_origin:check_index = [substr.start() for substr in re.finditer('\"', script_origin)]start_index = check_index[0]end_index = check_index[1]script_str = script_origin[start_index + 1:end_index]version_info = script_str.find('v=')if version_info > 0:script = script_str[:version_info - 1]else:script = script_strscript_origin = script_origin.replace(script_str, "{% static \'" + script + "\' %}")print(script_origin)if __name__ == '__main__':script = '''<script src="js/jquery.min.js?v=2.1.4"></script><script src="js/bootstrap.min.js?v=3.3.6"></script><script src="js/plugins/flot/jquery.flot.js"></script><script src="js/plugins/flot/jquery.flot.tooltip.min.js"></script><script src="js/plugins/flot/jquery.flot.spline.js"></script>'''change_static(script)

会打印:

<script src="{% static 'js/jquery.min.js' %}"></script>
<script src="{% static 'js/bootstrap.min.js' %}"></script>
<script src="{% static 'js/plugins/flot/jquery.flot.js' %}"></script>
<script src="{% static 'js/plugins/flot/jquery.flot.tooltip.min.js' %}"></script>
<script src="{% static 'js/plugins/flot/jquery.flot.spline.js' %}"></script>

django自动转化前端模板中static的css,js引用相关推荐

  1. HTML网页设计结课大作业~仿凡客服装商城主页纯HTML模板源码(HTML+CSS+JS)

    HTML网页设计结课作业~服装商城主页纯HTML模板源码(HTML+CSS+JS) 临近期末, 你还在为HTML网页设计结课作业,老师的作业要求感到头大?HTML网页作业无从下手?网页要求的总数量太多 ...

  2. 前端资源文件(图片 css js)同步到阿里云OSS

    前端资源文件(图片 css js)同步到阿里云OSS 需求: 为了实现自动化更新前端资源,前端资源已放到了阿里云OSS,实现自动上传. 思路: 1.因为使用的是php语言开发项目,自然会想到用php实 ...

  3. django怎么在html添加变量,如何在django项目的html模板中创建局部变量?

    我是python和django的初学者. 在这里我试图建立一个网站.在 我创建了一个名为cluster的类,它实际上意味着一个城镇或城市. 作为一个子类,我为集群创建了学校. 学校有一个领域schoo ...

  4. 在chrome-console中进行xpath/css/js定位

    一.Xpath console中调用xpath的基本格式:$x("xpath表达式") 1.1 绝对定位与相对定位 绝对定位:$x("/xpath表达式") 相 ...

  5. js date转成 时间字符串_秋招快要开始了,前端笔试中的坑位-JS隐式转换问题

    我们在写笔试题的时候,经常碰到涉及隐式转换的题目,例如 "1" + 2 obj + 1 [] == ![] [null] == false === 和 == === 叫做严格运算符 ...

  6. css grid随页面大小_前端开发中各种设置CSS间距的优点缺点及实例「实践」

    前言 如果两个或多个元素很接近,那么用户就会认为它们以某种方式属于彼此.当对多个设计元素进行分组时,用户可以根据它们之间的空间大小来决定它们之间的关系.没有间距,用户将很难浏览页面并知道哪些内容相关而 ...

  7. php在模板中传变量给js

    正确方式 var XXX = <?php echo json_encode($xx) ?>; 即使json_encode把中文转成了unicode编码,js接受变量时仍能恢复成中文. 错误 ...

  8. Web前端单词大全(html+css+js+vue)

    style 修饰 width 宽度 height 高度 title 想说明的 text-align 水平对齐方式 center 居中 left 居左 right 居右 line-height 垂直对齐 ...

  9. 前端单词大全(html+css+js+vue+小程序)

    样式代码单词 style 样式 width 宽度 height 高度 title 标题 text-align 水平对齐方式 center 居中 left 居左 right 居右 line-height ...

最新文章

  1. Mysql,SqlServer,Oracle主键自动增长的设置
  2. C#从零单排上王者系列---元组
  3. Go中有一个foreach循环吗?
  4. python将txt转换为csv_Python Pandas 三行代码将 txt 文件转换成 csv 文件
  5. C# 添加xml节点多了xmlns属性问题
  6. QT中处理不同Windows(窗体中的)消息
  7. mysql一列数据转为一行_MySQL高性能优化规范建议,速度收藏
  8. tar 命令详解 / xz 命令
  9. rzsz上传下载命令
  10. mac android手机录屏软件,Mac录屏软件推荐,比Quicktime好用!
  11. Day16:C++之STL应用篇(推箱子cxk限定)
  12. 树莓派51/100 - Pico下用MicroPython在ssd1306上显示汉字
  13. leetcode 算法题575 (简单147) 罗马数字转整数
  14. 视频直播中的心形漂浮效果
  15. 原创工具14Finger-全能web指纹识别与分享平台
  16. 马桶品牌十大排名榜2022 马桶什么牌子好又实惠
  17. 小程序全局拖动悬浮球插件
  18. laravel中公共子视图继承实现
  19. 元宇宙「虚拟世界」,构建身临其境的社交世界
  20. 【APUE笔记】第十二章 高级I/O

热门文章

  1. java决策树算法_「Smile」一下,轻松用Java玩转机器学习
  2. python 读写文件 另存为_python读写文件(五)
  3. EPIC《禅意花园》项目开放下载
  4. This is the default error page for nginx that is distributed with EPEL.
  5. Esper学习笔记四:EPL语法(2)
  6. 期权、RSU的区别与行权事宜
  7. 马行走路线的测试用例设计
  8. Nginx使用教程(八):使用Nginx缓存之Memcached缓存
  9. PVS的内存和存储规划设计
  10. 汇付天下支付使用 NPC_SERVER