Create 'Export As CSV' Button in Django on HTML Webpage [duplicate]

I currently have a working django application that has a view that outputs a dataframe and is rendered onto a .html page. Now, I am trying to create a button on this .html page that allows the user to download the rendered table to their local downloads folder.

How is this done? I am yet to figure it out after doing lots of research trying to get a table from views to html to downloaded as csv.

Thank you!

Python code in

results_html = results.to_html(index=False)
return render(request, 'output.html', {'results_html': results_html})

my current home.html code

<html lang="en-US">

I have looked into this and would like more clarification about where to type each thing.I am brand new to Django and still trying to figure out how each file interacts.

Back to Top