使用 Python 在城市售票网添加成功时,为网页增加声音提示功能
在网页中添加声音提示,能够增强用户体验,提高用户满意度。本文将介绍如何使用 Python 在城市售票网添加成功时,为网页增加声音提示功能。
首先需要准备好音频文件,一般格式为 .mp3、.wav 等。在此以 .mp3 格式的音频文件为例,将其命名为 success.mp3,并放置于项目目录下。
接着,使用 Flask 搭建一个简单的 Web 服务器:
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/success')
def success():
return render_template('success.html')
if __name__ == '__main__':
app.run(debug=True)
在项目目录下新建 templates 文件夹,并在其中新建两个 HTML 文件:index.html 和 success.html。
index.html:
<!DOC