使用flask框架从html播放wavefile? [英] Playing a wavefile from the html using flask framework?

查看:45
本文介绍了使用flask框架从html播放wavefile?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的run.py代码

This is my run.py code

        from flask import *

        app = flask.Flask(__name__)
        app.config.from_object('config')                          
        @app.route('/', methods=['GET','POST'])
        def new_task():
            if flask.request.method == 'POST':
               tts = flask.request.form['tts']
            if int(tts) == 3:
               return redirect("/tts1")
            function()
                flask.flash(str(tts)+'is being selected')
                   print str(tts)+"output"
            else:
               flask.flash('Parakrant ---->')
                return flask.render_template("tasks.html")
            return redirect('/') 
    @app.route('/tts1')
    def wav():
        print "wavfile reached"
        return flask.render_template("s1.html")

这是我的base.html文件

This my base.html file

    <html>
    <head>
        <title>names</title>
      </head>
      <body>
        <div>PS: <a href="/ps">Home</a></div>
        <hr>
        {% block content %}{% endblock %}
      </body>
    </html>

这是我的task.html

this my tasks.html

  {% extends "base.html" %}
  {% block content %}
  <div class="page">
  <table>
  <tr>
  <form action="{{ url_for('new_task') }}" method="POST" class=new-task>
 </tr>
  <tr>
   <td>
   <label>name :</label>
  <select name="name" width="100px">
   <option value="1">name1</option>
  <option value="2">name2</option>
   <option value="3">name3</option>
  <option value="4">name4</option>
  <option value="5">name5</option>
   </select>
  </td>
   <td>
   &nbsp;
   &nbsp;
    <input class="button" type="submit" value="Press">
   <audio controls>
   <source src="ps.wav" type="audio/wav">
  </audio>
   </td>
    </form>
   </tr>
  </table>
   </div>
   </table>
 {% endblock %}

这是我的s1.html

This my s1.html

    {% extends "base.html" %}
    {% block content %}
      <div class="page">
      <table>
      <tr>
      <form action="{{ url_for('new_task') }}" method="POST" class=new-task>
      </tr>
      <tr>
      <td>
      <label>name :</label>
      <select name="name" width="100px">
      <option value="1">name1</option>
      <option value="2">name2</option>
      <option value="3">name3</option>
      <option value="4">name4</option>
      <option value="5">name5</option>
      </select>
      </td>
      <td>
      &nbsp;
      &nbsp;
      <input class="button" type="submit" value="Press">
      <audio controls>
        <source src="ps.wav" type="audio/wav">
      </audio>
      </td>
      </form>
       </tr>
       </table>
       </div>
       </table>
    {% endblock %}

在s1.html中,我有一个指向音频wav文件的超链接.我想播放s1.html中的音频文件.wav文件位于根目录中.
它抛出错误

In the s1.html i have a hyperlink to a audio wav file . I want to play the audio file from the s1.html. The wav file is present in the root directory.
It is throwing error

GET/ps.wav HTTP/1.1"404请告诉您如何解决此问题.帮助将不胜感激!

GET /ps.wav HTTP/1.1" 404 Please tell how to solve this. Help will be highly appreciated!

推荐答案

如果您使用默认的静态文件配置运行Flask,则应将wave文件放在"static"文件夹中,然后在它们中引用它们.模板为

If you are running Flask with the default static file configuration, then you should place your wave files in the "static" folder, and then refer to them in your template as

{{ url_for("static", filename = "ps.wav") }}

这篇关于使用flask框架从html播放wavefile?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆