1

I have a html invoice file. Currently my django app is not serving it. I want to pass some variable to it and then download it as a HttpResponse.

My invoice file folder structure is like:

--someFolder/invoice(folder)
               |__ index.html
               |__ style.css
               |__ logo.png

I have a function in my models file like:

def createInvoice(self, po_number):
    po = self.purchase_orders.find_one({'po_number':po_number})

    total_po_qty = po['total_po_qty']
    po_subtotal = po['po_subtotal']
    tax_value = po['tax_value']
    shipping_value = po['shipping_value']
    total_po_value = po['total_po_value']
    vendor_name = po['vendor_name']
    tax_percent = po['tax_percent']
    tax_type = po['tax_type']
    expiry_date = po['expiry_date']
    sku_list = po['sku_list']

How can i pass these variables to the html file? I can render the file as a view but i dont want to do that since it is bound to a download button.

Manish Gupta
  • 4,438
  • 18
  • 57
  • 104
  • What does this mean? What is the point of "passing variables" to an HTML file that you're not even serving? – Daniel Roseman Jan 18 '16 at 13:08
  • I am not sure I understand what the goal is, since the description sounds contradictory. The view normally responds with an HTML generated (rendered) on the fly based on a template. The view can pass parameters to the renderer. – Pynchia Jan 18 '16 at 13:11
  • I was thinking of using wkhtmltopdf to convert that page as a pdf – Manish Gupta Jan 18 '16 at 13:13

1 Answers1

1

You can not "pass python variables" to a static HTML file, period, so you do have to use a view (and turn your HTML file into a template FWIW).

wrt/ "download" thing, forcing file download from a Django view is quite easy and documented - but then HTML is probably not the appropriate format, you may want to generate a PDF instead. NB : you may want read this answer for a way to generated PDF from HTML

Community
  • 1
  • 1
bruno desthuilliers
  • 75,974
  • 6
  • 88
  • 118