In my app.py
file, I have
@app.route('get_item')
def get_item():
id = request.args.get('id')
# if id is in database (if request is valid):
send_from_directory('files', 'file.ext', as_attachment=True)
else:
abort(403)
I have read in numerous SO posts that using Flask to serve static files is a bad idea for production purposes. What should I do instead if I am planning on using an Apache server for production?
Basically, you need some rewrite rules so that Apache can find the files, something like this:
Alias /static/ /var/www/hello-world/static
And redirect to apache when needed:
id = request.args.get('id')
# if id is in database (if request is valid):
return redirect('/files/file.ext') # use the correct url written in rewrite rules
else:
abort(403)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.