0

I want to create a generic "html table to excel file" view that can be used by several other views displaying query results in HTML tables. I thought I can add a parameter to every query view that makes it render the HTML without sending a response, but using it instead to feed a helper function that will parse it and convert the table rows and columns to Excel content by using the xlwt library.

Can I do this "render without response" in django?

4

1 回答 1

7

Yep

from django.template.loader import render_to_string
rendered = render_to_string('my_template.html', { 'foo': 'bar' })

here are the docs

于 2012-03-28T20:01:06.133 回答