• 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')
    

      

  • 相关阅读:
    sql中关于存在就不做操作的代码块
    mysql插入多条数据时间复杂度比较
    oracle in VS or效率
    如何实现分布式数据库
    angularJS操作键值对象(类似java的hashmap)填坑小结
    angularJS 如何读写缓冲
    angularJs自定义服务(实现签名和加密)
    ajax请求技术
    springboot中使用mybatis显示执行sql
    mysql快速生成truncate脚本清空数据库表记录
  • 原文地址:https://www.cnblogs.com/kekeoutlook/p/14169992.html
Copyright © 2020-2023  润新知