zoukankan      html  css  js  c++  java
  • flask文件路径设置问题

    服务默认了图片和其他资源有指定文件夹,但是我们不习惯指定的文件夹,更喜欢在工程目录下自定义文件夹地址存放不同的网页资源文件

    关键

    app = Flask(
        __name__,
        template_folder='.',  # 表示在当前目录 (myproject/A/) 寻找模板文件
        static_folder='',     # 空 表示为当前目录 (myproject/A/) 开通虚拟资源入口
        static_url_path='',
    )
    

      

    完整代码

    #激活环境
    
    #!/usr/bin/env python2
    # -*- coding: utf-8 -*-
    import time
    from flask import Flask, render_template, Response,request,redirect,url_for,jsonify,send_file, send_from_directory,json, jsonify,make_response
    from camera import VideoCamera
    import datetime,random #导入时间和随机数模块
    
    import cv2
    video=VideoCamera()
    app = Flask(__name__)
    
    import os
    pathnow=os.getcwd()
    pathnow=pathnow.replace('\','/')
    #print(pathnow) #获取当前工作目录路径
    #print (os.path.abspath('mainPage0.html'))
    
    HTML_PATH=pathnow
    
    app = Flask(
        __name__,
        template_folder='.',  # 表示在当前目录 (myproject/A/) 寻找模板文件
        static_folder='',     # 空 表示为当前目录 (myproject/A/) 开通虚拟资源入口
        static_url_path='',
    )
    
     
    @app.route('/')
    def index():
        return render_template('./215video/index_mp4.html')
    
    @app.route('/adjustPage')
    def add():
        return render_template('adjustPage.html')
    
    
    
    
     
    @app.route('/login', methods = ["GET","POST"])
    def login():
        name = request.args.get("username")
        password = request.args.get("userpwd")
        print('待验证账户:'+name+"   待验证密码:"+password)
        if name== 'admin' and password=='admin':
            
            #return redirect(url_for('use'))
            return '登录成功'
        else:
            return '登录失败'
         
     
    
     
     
    @app.route('/setData', methods = ["GET","POST"])
    def getvalue():
        now = datetime.datetime.now().strftime('%H:%M:%S')           
        data = {'time':now}
        return jsonify(data) #将数据以字典的形式传回
    
    
    
    
    #传输视频
    def gen(camera):
        while True:
            frame = camera.get_frame()
            
            yield (b'--frame
    '
                    b'Content-Type: image/jpeg
    
    ' + frame + b'
    
    ')
     
    @app.route('/video_feed')
    def video_feed():
        return Response(gen(video),mimetype='multipart/x-mixed-replace; boundary=frame')
    
    
    
    
     
    if __name__ == '__main__':
        app.run(host='0.0.0.0',port='8080')
    

      

  • 相关阅读:
    后台管理UI
    14.6.3.2 Configuring Multiple Buffer Pool Instances 配置多个Buffer Poll 实例:
    14.6.3.1 The InnoDB Buffer Pool
    innodb_buffer_pool_instances and innodb_buffer_pool_size的关系
    猪肉都被绑上了“家族标签”,大数据已波及到农牧业!
    14.6.2 Configuring InnoDB for Read-Only Operation
    jquery EasyUI datagrid重新加载传参问题
    分布式系统事务一致性解决方案
    面试题整理
    dump iot表
  • 原文地址:https://www.cnblogs.com/kekeoutlook/p/14169992.html
Copyright © 2011-2022 走看看