静态文件:css文件,js文件,图片等
1,加载静态文件使用的是'url_for'函数,然后第一个参数是‘static’,第二个参数需要为一个关键字参数‘filename=‘路径’。示例:
<head> <meta charset="UTF-8"> <title>知了课堂</title> <link rel="stylesheet" href="{{ url_for('static',filename="css/index.css")}}"> <script src="{{ url_for('static',filename='js/index.js') }}"> </script> </head> <body> <img src="{{ url_for('static',filename='img/cheliang.png',alt='') }}"> </body>路径查找要以当前项目的‘static’目录作为根目录。
本文介绍了如何在Flask框架中加载和引用静态文件,如CSS、JavaScript和图片。关键在于利用'url_for'函数,传入'static'作为第一个参数,再以'filename='指定文件路径。
412

被折叠的 条评论
为什么被折叠?



