Project name :Flask_Plan
templates:
默认设置下,Flask在程序根目录中名为static的子目录中寻找静态文件。
随便找个图片放进去把,命令test.png
Flask_Plan/static/test.png
修改模板文件Flask_Plan/templates/plan.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <h1>这是计划页面</h1> <img src="{{ url_for('static', filename='test.png') }}"> </body> </html>
模板文件中使用
{{ url_for('static', filename='test.png') }}
来表示static目录下的test.png
当然我们也要引用更多的静态文件。
templates建立文件夹分类管理吧。
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Title</title> <!-- Bootstrap --> <link href="{{ url_for('static', filename='css/bootstrap.css')}}" rel="stylesheet"> <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> <!-- WARNING: Respond.js doesn't work if you view the page via file:// --> <!--[if lt IE 9]> <script src="{{ url_for('static', filename='js/html5shiv.min.js') }}"></script> <script src="{{ url_for('static', filename='js/respond.min.js') }}"></script> <![endif]--> <!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> <script src="{{ url_for('static', filename='js/jquery-3.2.1.min.js') }}"></script> <!-- Include all compiled plugins (below), or include individual files as needed --> <script src="{{ url_for('static', filename='js/bootstrap.js') }}"></script> </head> <body> <h1>这是计划页面</h1> <img src="{{ url_for('static', filename='test.png') }}"> </body> </html>
我下载了jquery bootstrap,并且引入。