fork(1) download
  1. import os
  2. from flask import Flask, request, redirect, url_for, send_from_directory, render_template
  3. from werkzeug.utils import secure_filename
  4.  
  5. UPLOAD_FOLDER = 'C:\Python27\Hernya'
  6. ALLOWED_EXTENSIONS = set(['png', 'jpg', 'jpeg'])
  7.  
  8. app = Flask(__name__)
  9. app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
  10.  
  11. def allowed_file(filename):
  12. return '.' in filename and \
  13. filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS
  14.  
  15. @app.route('/', methods=['GET', 'POST'])
  16. def upload_file():
  17. if request.method == 'POST':
  18. file = request.files['file']
  19. if file and allowed_file(file.filename):
  20. filename = secure_filename(file.filename)
  21. file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
  22. return redirect(url_for('uploaded_file',
  23. filename=filename))
  24. return render_template("t1.html")
  25.  
  26. @app.route('/uploads/<filename>')
  27. def uploaded_file(filename):
  28. return render_template('t2.html', filename=filename)
  29.  
  30. if __name__=="__main__":
  31. app.run(debug=True)
Runtime error #stdin #stdout #stderr 0.01s 8968KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "prog.py", line 2, in <module>
ImportError: No module named flask