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,并且引入。

  • 相关阅读:
    视频处理类
    JAVA向EXE文件尾追加配置信息,用于解决局版客户端的程序IP配置问题
    分布式系统解决方案
    理想智慧云
    在C#中调用格式工厂进行任意视频格式到FLV的转换
    思考一下提高转码的速度
    在OpenResty中使用淘宝的concat进行css和js合并,同时支持GZIP静态压缩
    robotframework常用的几个快捷键
    robotframe使用之滚动条
    robotframe使用之时间控件
  • 原文地址:https://www.cnblogs.com/jackadam/p/8128156.html
Copyright © 2011-2022 走看看