Advertisement
Guest User

Untitled

a guest
Mar 30th, 2024
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.68 KB | None | 0 0
  1. from flask import Flask, render_template, request
  2. import os
  3.  
  4. app = Flask(__name__)
  5.  
  6. UPLOAD_FOLDER = 'uploads'
  7. app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
  8.  
  9. if not os.path.exists(UPLOAD_FOLDER):
  10.     os.makedirs(UPLOAD_FOLDER)
  11.  
  12. @app.route('/')
  13. def index():
  14.     return render_template('index.html')
  15.  
  16. @app.route('/upload', methods=['POST'])
  17. def upload():
  18.     if 'file' not in request.files:
  19.         return 'No file part'
  20.    
  21.     files = request.files.getlist('file')
  22.    
  23.     for file in files:
  24.         file.save(os.path.join(app.config['UPLOAD_FOLDER'], file.filename))
  25.    
  26.     return 'Files uploaded successfully'
  27.  
  28. if __name__ == '__main__':
  29.     app.run(debug=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement