by jirawoot » 02/07/2019 11:10 am
mindphp wrote:ตัวอย่าง flask กำหนด headers เอง
Code: Select all
from flask import make_response
@app.route('/docs/<id>')
def get_pdf(id=None):
if id is not None:
binary_pdf = get_binary_pdf_data_from_database(id=id)
response = make_response(binary_pdf)
response.headers['Content-Type'] = 'application/pdf'
response.headers['Content-Disposition'] = \
'inline; filename=%s.pdf' % 'yourfilename'
return response
ส่วนสำคัญคือตรงนี้
Code: Select all
response.headers['Content-Type'] = 'application/pdf'
Code: Select all
binary_pdf = get_binary_pdf_data_from_database(id=id)
response = make_response(binary_pdf)
ในส่วนนี้ id ต้องมาจาก database หรอครับ
[quote="mindphp"]ตัวอย่าง flask กำหนด headers เอง
[code]from flask import make_response
@app.route('/docs/<id>')
def get_pdf(id=None):
if id is not None:
binary_pdf = get_binary_pdf_data_from_database(id=id)
response = make_response(binary_pdf)
response.headers['Content-Type'] = 'application/pdf'
response.headers['Content-Disposition'] = \
'inline; filename=%s.pdf' % 'yourfilename'
return response[/code]
ส่วนสำคัญคือตรงนี้
[code]response.headers['Content-Type'] = 'application/pdf'[/code][/quote]
[code]
binary_pdf = get_binary_pdf_data_from_database(id=id)
response = make_response(binary_pdf)
[/code]
ในส่วนนี้ id ต้องมาจาก database หรอครับ