One potential issue in the code is that the variable fname is being used in
the Content-Disposition header, but it's not defined in the provided
snippet. Make sure that fname is defined and contains the desired filename
for the CSV file.

Additionally, it's important to ensure that the make_csv function correctly
constructs the CSV content and that it's being called with the correct data.

On Tue, Jan 2, 2024 at 7:45 AM Mike Dewhirst <mi...@dewhirst.com.au> wrote:

> I wonder if someone can point out my mistake?
>
> The following code happily downloads a constructed text file ...
>
>     csv = make_csv(context['result'])
>
>     # This downloads a csv file to the user desktop
>
>     return HttpResponse(
>
>         csv,
>
>         headers={
>
>             'Content-Type': 'text/plain',
>
>             # Set the content-disposition header to prompt user download
>
>             'Content-Disposition': f'attachment; filename="{fname}.csv"'
>
>         },
>
>     )
>
>
> ... but leaves all the entered (unbound) form data on display. However, I
> want the form cleared ready for the next set of user data.
>
> The following code clears the entered data but fails to download the
> constructed file.
>
>     csv = make_csv(context['result'])
>
>     # This fails to download a csv file
>
>     return HttpResponseRedirect(
>
>         "",
>
>         csv,
>
>         headers={
>
>             'Content-Type': 'text/plain',
>
>             # Set the content-disposition header to prompt user download
>
>             'Content-Disposition': f'attachment; filename="{fname}.csv"'
>
>         },
>
>     )
>
>
> Many thanks for any help
>
> Cheers
>
> Mike
>
> --
>
> Signed email is an absolute defence against phishing. This email has
> been signed with my private key. If you import my public key you can
> automatically decrypt my signature and be sure it came from me. Your
> email software can handle signing.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/3b59be97-0cf9-4654-97ac-86da72ed4737%40dewhirst.com.au
> <https://groups.google.com/d/msgid/django-users/3b59be97-0cf9-4654-97ac-86da72ed4737%40dewhirst.com.au?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACng%3DehTc%3DoSoFMbW4UGz7LNSkUWaAAXhkGWb-9t45K6RLs2rQ%40mail.gmail.com.

Reply via email to