import os
from flask import Flask, request, redirect, url_for, send_from_directory, render_template
from werkzeug.utils import secure_filename
UPLOAD_FOLDER = 'C:\Python27\Hernya'
ALLOWED_EXTENSIONS = set(['png', 'jpg', 'jpeg'])
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS
@app.route('/', methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST':
file = request.files['file']
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
return redirect(url_for('uploaded_file',
filename=filename))
return render_template("t1.html")
@app.route('/uploads/<filename>')
def uploaded_file(filename):
return render_template('t2.html', filename=filename)
if __name__=="__main__":
app.run(debug=True)
aW1wb3J0IG9zCmZyb20gZmxhc2sgaW1wb3J0IEZsYXNrLCByZXF1ZXN0LCByZWRpcmVjdCwgdXJsX2Zvciwgc2VuZF9mcm9tX2RpcmVjdG9yeSwgcmVuZGVyX3RlbXBsYXRlCmZyb20gd2Vya3pldWcudXRpbHMgaW1wb3J0IHNlY3VyZV9maWxlbmFtZQoKVVBMT0FEX0ZPTERFUiA9ICdDOlxQeXRob24yN1xIZXJueWEnCkFMTE9XRURfRVhURU5TSU9OUyA9IHNldChbJ3BuZycsICdqcGcnLCAnanBlZyddKQoKYXBwID0gRmxhc2soX19uYW1lX18pCmFwcC5jb25maWdbJ1VQTE9BRF9GT0xERVInXSA9IFVQTE9BRF9GT0xERVIKCmRlZiBhbGxvd2VkX2ZpbGUoZmlsZW5hbWUpOgogICAgcmV0dXJuICcuJyBpbiBmaWxlbmFtZSBhbmQgXAogICAgICAgICAgIGZpbGVuYW1lLnJzcGxpdCgnLicsIDEpWzFdIGluIEFMTE9XRURfRVhURU5TSU9OUwoKQGFwcC5yb3V0ZSgnLycsIG1ldGhvZHM9WydHRVQnLCAnUE9TVCddKQpkZWYgdXBsb2FkX2ZpbGUoKToK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