플라스크 앱 디렉토리에 일반 아파치 웹 서버 처럼 DocumentRoot 경로에 파일을 업로드하고 요청을 시도하면 404 또는 500 에러를 응답 받는다.




flask 앱에서는 send_from_directory 모듈을 사용하여 일반 아파치 서버 처럼 파일을 업로드하고 다운로드 받을 수 있다.


1
2
3
4
5
6
7
from flask import send_from_directory
 
...
 
 @app.route('/file/<path:filename>', methods=['GET', 'POST'])
 def download(filename):
     return send_from_directory(directory='file', filename=filename)
cs


file 이라는 서브 디렉토리 생성 후, 해당 위치에 파일을 업로드하고, flask 앱 라우팅을 통해 해당 경로에서 파일을 다운로드 받을 수 있도록 설정하면 된다.

'Python' 카테고리의 다른 글

pipsi - pip script installer  (1) 2019.06.04
SSH with python3  (0) 2019.01.25
Flask on apache via mod_wsgi  (0) 2018.12.06
Python 2.6 to 2.7 (or 3.x)  (0) 2018.11.23
Django: 1. Start first application  (0) 2018.05.30

+ Recent posts