简体   繁体   English

何在 django 中创建下载链接

[英]Ho to create download link in django

I created a Django project which I use in Apache server.我创建了一个 Django 项目,我在 Apache 服务器中使用它。

The project simply edits an .m3u file when you press a button on a page, and generates a new .m3u file.当您按下页面上的按钮时,该项目只需编辑一个.m3u文件,并生成一个新的.m3u文件。 The script works as intended.该脚本按预期工作。

Can Django generate a download link automatically for this newly generated .m3u file? Django 能否自动为这个新生成的.m3u文件生成下载链接? I understand from many tutorials that I need to edit the urls.py and view.py files, but I need it to be done automatically.我从许多教程中了解到我需要编辑urls.pyview.py文件,但我需要自动完成。

Or another option would be to make the file downloadable via Apache directly if something like this is possible.或者,如果可能的话,另一种选择是直接通过 Apache 使文件可下载。

is that is it possible Django can generate a download link automatically for this newly generated m3u file是否有可能 Django 可以为这个新生成的 m3u 文件自动生成下载链接

Yes.是的。 I assume this is a static file located somewhere on the server.我假设这是位于服务器某处的 static 文件。 You can make file generator script/function return the location of generated file on server.您可以使文件生成器脚本/函数返回生成文件在服务器上的位置。 The download URL can take location of this fileas a query parameter.下载 URL 可以将此文件的位置作为查询参数。 You can make this file available using Django .您可以使用 Django 使该文件可用

Or another option would be to make the file downloadable via apache diretly if something like this is possible.或者,如果可能的话,另一种选择是直接通过 apache 使文件可下载。

Yes, you can.是的你可以。 See Can you make a file downloadable through Apache?请参阅您可以通过 Apache 使文件可下载吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM