Python 3.x 使用Raspberrypi上的flask Web服务器捕获照片

Python 3.x 使用Raspberrypi上的flask Web服务器捕获照片,python-3.x,flask,raspberry-pi,Python 3.x,Flask,Raspberry Pi,这是我调用函数的按钮,但当我按下它时,它只是刷新页面 href="{{ url_for('takephoto') }}"><input type="button" value="takephoto"> 你可能想处理这个问题 我现在没有可供测试的Pi,但类似于: import io import time import picamera @app.route('/camera',methods=['POST']) def takephoto(): # Create a

这是我调用函数的按钮,但当我按下它时,它只是刷新页面

href="{{ url_for('takephoto') }}"><input type="button" value="takephoto">
你可能想处理这个问题

我现在没有可供测试的Pi,但类似于:

import io
import time
import picamera

@app.route('/camera',methods=['POST'])
def takephoto():
    # Create an in-memory stream
    my_stream = io.BytesIO()
    with picamera.PiCamera() as camera:
        camera.start_preview()
        # Camera warm-up time
        time.sleep(2)
        camera.capture(my_stream, 'jpeg')

    my_stream.seek(0)
    return send_file(my_stream.read(), mimetype='image/jpeg')
然后有一个单独的路由来呈现模板:

@app.route('/')
def index():
    return render_template('index.html')
<img src="{{ url_for('takephoto') }}" />
在模板中使用此选项:

@app.route('/')
def index():
    return render_template('index.html')
<img src="{{ url_for('takephoto') }}" />

重新加载该页面应捕获新图像