download.html 渲染后如何创建下载路径

问题描述

我一直在研究这个...渲染模板后,我无法在我的 download.html 中创建下载链接。该代码在终端上运行良好,并且还将文件移动到特定文件夹,但我无法为其创建下载链接

我尝试使用元标记自动下载 download.html 以获取文件,但收到路径错误消息

<Meta http-equiv="refresh" content="0; url=yourfile.mp3">

所以我尝试使用下面的下载链接是我在控制台上下载的代码

@bp.route('/download/<mp3>')
def download(mp3):
return send_file(mp3,as_attachment=True)

@bp.route("/get_mp3",methods=['GET','POST'])
def get_mp3():
url = video_url
    yt = pytube.YouTube(url)
    title = yt.title
    local_src = os.path.dirname(os.path.realpath(__file__))
    destination = '/'+ title

    src = local_src + destination
    dst_mp3 = src + title
    
flash("Download....!!!")
    
    
    mp4 = YouTube(url).streams.get_highest_resolution().download()
    mp3 = mp4.split(".mp4",1)[0] + f".mp3"

    video_clip = VideoFileClip(mp4)
    audio_clip = video_clip.audio
    audio_clip.write_audiofile(mp3)

    audio_clip.close()
    video_clip.close()

    
    os.remove(mp4)
    shutil.move(os.path.join(src,mp3),os.path.join("flaskr\\mp3\\",mp3))
    return render_template('promote.html',attachment_filename=mp3,as_attachment=True)
<a href="/download/<mp3>"><button class="btn btn-primary">Download Mp3</button></a>

这是触发进程的javascript函数

<script type=text/javascript>
        $(function() {
          $('a#test').on('click',function(e) {
            e.preventDefault()
            $.getJSON('/get_mp3',function(data) {
              //do nothing
               myFunction()
            });
            return false;
          });
        });
</script>


<form action="/get_mp3" method="post">
<button name="get_mp3" type="submit" id="music-download" class="btn btn-outline-warning downloadbtn" onclick="myFunction();">
<a  name="get_mp3" type="submit"><i class="fas fa-cloud-download-alt" style="color: white;"> MP3</i></a></button> 
</form>

就像我说的......这个过程运行良好,但无法通过我的浏览器从 download.html 下载它。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...