return message after file download in Django view response
Asked Answered
I

1

6

I am downloading a pandas data-frame as a csv file using this approach:

view.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

in my html, I have ...

<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>

The file export works fine. However, after the export is done, I need to be able to show a message on the html page .... something like {{ my_message}} without reloading the page.

if this is feasible, I would appreciate any suggestion on how to do this, without resorting to AJAX, which I abandoned because some of the downloads can be large.

Itol answered 23/7, 2019 at 16:2 Comment(0)
N
0

use message.success ("your message goes here") in you html file {% if messages%} {%for msg in messages%}

{{msg}}

{%endfor%} {%endif%}

Nipissing answered 23/7, 2019 at 17:12 Comment(2)
I already have this coded . It won't work as is ... I need something to trigger an event after the form is submitted.Itol
if yoi are using class base views then only successMessagemixin will work.Nipissing

© 2022 - 2024 — McMap. All rights reserved.