I have a template page on which one I access when I filled my `Django form`. This page is a simple `HTML page` with data coming from my form. I would like to be able to download the filled template. That's to say, get a browser window which let to download the template or by clicking on a button which will save the HTML template somewhere.
This is my code in my **views.py** file: class TemplateGenerator(TemplateView): ''' This class displays the form and lets to save data into my database. It redirects users to the filled HTML template ''' form_class = CommunicationForm template_name = 'form.html' success_url = '/HTML_Result/' def get(self, request): form = self.form_class() return render(request, self.template_name, {'form': form}) def post(self, request): form = self.form_class(request.POST, request.FILES) if form.is_valid(): form.save() return redirect('HTML_Result') args = {'form': form} return render(request, self.template_name, args) class HTMLResult(TemplateView): ''' This class displays the template filled thanks to the form from TemplateGenerator() class ''' template_name = 'template_1.html' def get(self, request): data = Communication.objects.values().latest('id') self.donwload_html() return render(request, self.template_name, {'data': data}) def donwload_html(self): file_path = os.path.join(settings.MEDIA_ROOT, 'media') if os.path.exists(file_path): with open(file_path, 'rb') as fh: response = HttpResponse(fh.read(), content_type= "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") response['Content-Disposition'] = 'inline; filename=' + 'test' return response raise Http404 I know I need to use `Content-Disposition` in order to download the HTML page, but I don't find a way to use it correctly. Do you have any idea ? Thank you by advance -- 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/b2cc33dc-1af2-45d0-b8b5-c6b95267beff%40googlegroups.com.