Answer the question
In order to leave comments, you need to log in
How to view downloaded Flask Python files after download?
I have a code (however, the standard one for loading is simple).
It allows you to select a file, everything is fine, it says that we have selected it, but
after clicking on the Upload button, it gives out: an internal server error
The server encountered an internal error and could not fulfill the request. Either the server is overloaded or an error has occurred in the application.
from flask import Flask, request, render_template
app = Flask(__name__)
@app.route('/upload', methods = ["Get","Post"])
def upload_file():
if request.methods == "POST":
f=request.files['the_file']
f.save('/var/www/uploads/uploads_file.txt')
return render_template("index2.html") #Шаблон, форма стандартная.
if __name__ == "__main__":
app.run()
Answer the question
In order to leave comments, you need to log in
from flask.pocoo.org/docs/1.0/patterns/fileuploads :
file.save(...)
# после сохранения файла сделать редирект
return redirect(url_for('uploaded_file', filename=filename))
from flask import send_from_directory
@app.route('/uploads/<filename>')
def uploaded_file(filename):
return send_from_directory(app.config['UPLOAD_FOLDER'], filename)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question