django - 在 Django 查看响应中下载文件后返回消息
问题描述
我正在使用这种方法将 pandas 数据帧下载为 csv 文件:
视图.py ....
response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename="' + filename + '"'
my_df.to_csv(response, encoding='utf-8', index=False, )
return response
在我的html中,我有...
<form class="default_form" method="POST" action="do_export">
{% csrf_token %}
<br/>
<input type="submit" class="btn btn-primary exportOut" value="Do Export"
id="myExport"/>
<br/>
</form>
文件导出工作正常。但是,在导出完成后,我需要能够在 html 页面上显示一条消息 .... 类似 {{ my_message}} 的内容,而无需重新加载页面。
如果这是可行的,我会很感激任何关于如何做到这一点的建议,而不是诉诸 AJAX,我放弃了 AJAX,因为有些下载可能很大。
解决方案
在你的 html 文件中使用 message.success (“你的消息在这里”) {% if messages%} {%for msg in messages%}
{{味精}}
{%endfor%} {%endif%}
推荐阅读
- regex - Regex: a character should not come consecutively not more than 3 times
- apache-spark - 默认情况下,spark 在哪个文件系统中查找读取文件?
- android - 如何解决此错误“com.google.ads.mediation.admob.AdMobAdapter cannot be cast to com.google.android.gms.ads.mediation.m”?
- c# - 在 MacBook Pro 中的 Visual Studio 代码上运行 .Net 应用程序
- smt - CVC4 相当于 Z3 的 seq.unit
- java - TCP 反向代理 Minecaft 未发送原始 IP
- javascript - 是否可以更新 Mongoose 文档中的对象?
- entity-framework - Scaffold-DbContext EF Core 时出现不明确的列名错误
- python - Django 查询集 order_by 绝对值
- c# - 我在 C# 中的类、结构或接口成员声明中收到错误无效标记“=”