librelist archives

« back to archive

Playing a wav file from html in flask

Playing a wav file from html in flask

From:
Parakrant Sarkar
Date:
2013-06-28 @ 09:37
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")

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>

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>
    
    
    <input class="button" type="submit" value="Press">
   <audio controls>
   <source src="ps.wav" type="audio/wav">
  </audio>
   </td>
    </form>
   </tr>
  </table>
   </div>
   </table>
 {% endblock %}

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>
       
       
      <input class="button" type="submit" value="Press">
      <audio controls>
        <source src="ps.wav" type="audio/wav">
      </audio>
      </td>
      </form>
       </tr>
       </table>
       </div>
       </table>
    {% endblock %}

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 Please tell how to solve this. Help will be
highly appreciated!


-- 
Parakrant Sarkar
Senior Scientific Officer
School of Information Technology
IIT Kharagpur - 721302
Mobile: +919007573677,
Email: parakrantsarkar@gmail.com <Email%3Aparakrantsarkar@gmail.com>,
parakrantsarkar@sit.iitkgp.ernet.in<http://parakrantsarkar.sit.iitkgp.ernet.in>

Re: [flask] Playing a wav file from html in flask

From:
John Hutchison
Date:
2013-06-28 @ 22:17
>> GET /ps.wav HTTP/1.1" 404 Please tell how to solve this. Help will be
highly appreciated!

So static files are normally in the static directory, you want to reflect
that. Normally with a {{ url_for( "static", "ps.wav") }} where the src is
in the HTML.