zoukankan      html  css  js  c++  java
  • Flask初级(四)flash在模板中使用静态文件

    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>
    View Code
    模板文件中使用
    {{ 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,并且引入。

  • 相关阅读:
    Cesium入门-2-增加地形
    Cesium中常用的一些地理数据文件 以及数据相关的东西
    飞行姿态角度表示: heading pitch roll
    Cesium入门-3-官方完整实例
    Cesium中级教程6
    Postgresql添加/删除触发器示例
    VUE课程---6、v-text和v-html指令
    VUE课程---5、vue devtools
    VUE课程---4、MVVM原理
    js简单对象(plain javascript object)
  • 原文地址:https://www.cnblogs.com/jackadam/p/8128156.html
Copyright © 2011-2022 走看看