{"action":"created","issue":{"url":"https://api.github.com/repos/SimonSapin/Flask-WeasyPrint/issues/8","labels_url":"https://api.github.com/repos/SimonSapin/Flask-WeasyPrint/issues/8/labels{/name}","comments_url":"https://api.github.com/repos/SimonSapin/Flask-WeasyPrint/issues/8/comments","events_url":"https://api.github.com/repos/SimonSapin/Flask-WeasyPrint/issues/8/events","html_url":"https://github.com/SimonSapin/Flask-WeasyPrint/issues/8","id":74459819,"number":8,"title":"using download_filename in render_pdf changes functionality","user":{"login":"SirNeuman","id":6912634,"avatar_url":"https://avatars.githubusercontent.com/u/6912634?v=3","gravatar_id":"","url":"https://api.github.com/users/SirNeuman","html_url":"https://github.com/SirNeuman","followers_url":"https://api.github.com/users/SirNeuman/followers","following_url":"https://api.github.com/users/SirNeuman/following{/other_user}","gists_url":"https://api.github.com/users/SirNeuman/gists{/gist_id}","starred_url":"https://api.github.com/users/SirNeuman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SirNeuman/subscriptions","organizations_url":"https://api.github.com/users/SirNeuman/orgs","repos_url":"https://api.github.com/users/SirNeuman/repos","events_url":"https://api.github.com/users/SirNeuman/events{/privacy}","received_events_url":"https://api.github.com/users/SirNeuman/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-05-08T18:56:41Z","updated_at":"2015-05-08T19:22:49Z","closed_at":"2015-05-08T19:22:49Z","body":"Previously I used:\r\nPython:\r\n```\r\nAPP.route(\"/to-pdf/<string:id>\")\r\ndef to_pdf(id):\r\n    ...\r\n    html = render_template('pdf.html', id=id)\r\n    return render_pdf(HTML(string=html))\r\n```\r\nHTML: `<a href=\"/to-pdf/{{id}}\" target=\"_blank\">`\r\n\r\nAnd it worked as expected. Upon clicking the a-tag the browser would display the pdf in a new tab. However I decided that i wanted a specific filename for when users downloaded the pdf from the browser. so i changed the Python to:\r\n```\r\nAPP.route(\"/to-pdf/<string:id>\")\r\ndef to_pdf(id):\r\n    ...\r\n    html = render_template('pdf.html', id=id)\r\n    pdf_filename = \"PDF-\" + id\r\n    return render_pdf(HTML(string=html), download_filename=pdf_filename)\r\n```\r\nAs per the flask-weasyprint documentation. Now, however, upon clicking the a-tag a new tab does not open, and it just downloads directly to the computer without a preview. It still generates the same pdf, but I would like it to keep the functionality as before with the addition of a default custom filename. So basically I'm wondering how i can set the default filename for downloading a file, without changing the url and while still allowing the pdf to be viewable in the browser (i.e. not download directly to the computer). Thanks\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/SimonSapin/Flask-WeasyPrint/issues/comments/100332901","html_url":"https://github.com/SimonSapin/Flask-WeasyPrint/issues/8#issuecomment-100332901","issue_url":"https://api.github.com/repos/SimonSapin/Flask-WeasyPrint/issues/8","id":100332901,"user":{"login":"SimonSapin","id":291359,"avatar_url":"https://avatars.githubusercontent.com/u/291359?v=3","gravatar_id":"","url":"https://api.github.com/users/SimonSapin","html_url":"https://github.com/SimonSapin","followers_url":"https://api.github.com/users/SimonSapin/followers","following_url":"https://api.github.com/users/SimonSapin/following{/other_user}","gists_url":"https://api.github.com/users/SimonSapin/gists{/gist_id}","starred_url":"https://api.github.com/users/SimonSapin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SimonSapin/subscriptions","organizations_url":"https://api.github.com/users/SimonSapin/orgs","repos_url":"https://api.github.com/users/SimonSapin/repos","events_url":"https://api.github.com/users/SimonSapin/events{/privacy}","received_events_url":"https://api.github.com/users/SimonSapin/received_events","type":"User","site_admin":false},"created_at":"2015-05-08T19:22:49Z","updated_at":"2015-05-08T19:22:49Z","body":"That’s not how browsers work. The `download_filename=\"foo\"` parameters makes Flask-WeasyPrint add the `Content-Disposition: attachment; filename=\"foo\"` header to the HTTP response. It’s that `attachment` value that makes browsers download a file rather than show it themselves, and the file name can not be specified without it.\r\n\r\nWithout a `Content-Disposition` header, browsers typically infer a file name from the last component of the path of the URL. You could have you Flask routes chosen accordingly. For example:\r\n\r\n```python\r\nAPP.route(\"/to-pdf/PDF-<string:id>.pdf\")\r\ndef to_pdf(id):\r\n    ...\r\n```\r\n\r\nBy the way, you could use something like [`{{ url_for('to_pdf', id=id) }}`](http://flask.pocoo.org/docs/0.10/api/#flask.url_for) in your HTML template to avoid hard-coding URLs."}}