Reputation: 11
flask code
@app.route('/usecase/get/excel/<heads>', methods=['GET', 'POST'])
def get_excel(heads):
headers = {"Content-Disposition": "attachment; filename=%s" % "usecase.xls"}
with open("usecase.xls", 'r') as f:
body = f.read()
return Response(response=(body, headers))
html code
<form action="/template/usecase/get/excel/" method="post">
<button type="submit" class="btn btn-info">download</button>
</form>
if click download button, error occured "Method not allowed".. and how to download server's file? this is exactly program?
Upvotes: 1
Views: 147
Reputation: 71
Are you matching the right route?
/template/
does not seem to be part of your routing rules unless its some root prefix. Secondly the heads
attribute is not optional so you will not hit that route anyway with that request.
On a more picky note: Why are you using a POST request to fetch the data when you clearly imply that you support the GET version.
Upvotes: 2