Diferencia entre revisiones de «Usuario:Lmorillas/desarrollo web servidor/flask/subir archivos»
De WikiEducator
(Página creada con '{{MiTitulo|Subir archivos}} <source lang="html4strict"> <form method=post enctype=multipart/form-data> <input type=file name=file> <input type=submit value=Attach> </form> …') |
|||
Línea 9: | Línea 9: | ||
<source lang="python"> | <source lang="python"> | ||
+ | from werkzeug import secure_filename | ||
+ | |||
+ | FILE_FOLDER = '...' | ||
+ | |||
@app.route('...', methods=['POST']) | @app.route('...', methods=['POST']) | ||
def file_attach(): | def file_attach(): |
Última revisión de 03:44 11 nov 2013
<form method=post enctype=multipart/form-data> <input type=file name=file> <input type=submit value=Attach> </form>
from werkzeug import secure_filename FILE_FOLDER = '...' @app.route('...', methods=['POST']) def file_attach(): # Match name from <input type=file name=file>: 'file'. filestorage = request.files['file'] # Do not allow '..' in the filename. filename = secure_filename(filestorage.filename) dest = os.path.join(FILE_FOLDER, filename) filestorage.save(dest) return 'Put your response here.'