> On 25 Jan 2015, at 07:37, Adam Morris <[email protected]> wrote:
> 
> I have a view that serves up a page that whose template/css contain both 
> define screen and print media. Which means the view's renderer provides a 
> page that serves up html that is formatted for the browser (screen media) and 
> if the user prints it formatted for the page (the print media). The CSS that 
> does this is:
> 
>   <link rel="stylesheet" href="${static_url}css/reports.css" media="screen">
>   <link rel="stylesheet" href="${static_url}css/reports_pdf.css" 
> media="print">
> 
> I want to add a view that returns a FileResponse, as rendered by the print 
> media, so that particular location results in a download of that PDF, but I 
> don't want to repeat code.
> 
> I don't want to serve a static asset, I want the PDF to be dynamically 
> created.
> 
> Any ideas on how to tackle this best?

Here is an example: 
https://github.com/wichert/checking/blob/master/src/checking/invoice.py#L306 
<https://github.com/wichert/checking/blob/master/src/checking/invoice.py#L306>

The basic approach is: generate your data (in this case the PDF file), create a 
response object using your data, set the right headers for it and return it 
from your view.

Wichert.

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pylons-discuss.
For more options, visit https://groups.google.com/d/optout.

Reply via email to