0

I am working on deploying a django app to heroku and I am having trouble with the webbrowser module. The function initially creates a pdf from html using pdfkit (this part works fine). Afterwards, I use '''webbrowser.open_new_tab''' to render the pdf in a new tab. This works perfectly locally, but not when I deploy to Heroku :( I checked the Heroku log, and it indicates that the pdf is being properly compiled and that the webbrowser command is successfully called, but alas, a new tab is not opened... Are there any suggestions on how best to tackle this issue? Perhaps I am missing an important environment variable that allows me to open new pages on the user's browser?

Thank you,

-- Carter

  • No. How could this possibly work? It can only control a browser on the local machine. – Daniel Roseman Nov 29 '19 at 18:40
  • Ah ok! I did not realize this... thank you! Do you have any suggestions on a different module? I would like to either render the pdf or have it download to the user's downloads folder. – Carter Rhea Nov 29 '19 at 18:43
  • You don't want a "module". You have to think in the context of the web. If you want to open a link in a new tab, then there needs to be something in that link itself to do so - ie `target="_new"`, or some JS. – Daniel Roseman Nov 29 '19 at 18:44
  • To elaborate on what @DanielRoseman suggested, create a view that returns a [FileResponse](https://docs.djangoproject.com/en/2.2/ref/request-response/#fileresponse-objects) with your PDF file created by `pdfkit`. If you want it to download, you can just link to this view function somewhere on another page and use `as_attachment=True`, and if you want it to open in a new tab then [see this question](https://stackoverflow.com/q/17711146/9374673). – Mihai Chelaru Nov 29 '19 at 20:15

0 Answers0