How to let Django fill an html template, then let the user download it without showing it in browser?
<p>I have an HTML template, and I want django to fill it with some data, but rather than redirect the user to a view that uses this template, I want Django to send the filled-template to the user as a download file.<br><br>
Any suggestions?</p>

<p>You create a regular view, but before returning the response, you set the HTTP Header <code>Content-Disposition</code>.</p>

<pre><code>def download_form(request):
    form = ...
    response = render(request, 'form_template.html', {'form': form})
    response['Content-Disposition'] = 'attachment; filename="form.html"'
    return response
</code></pre>

python django python-2.7 django-templates