Skip to content

Commit

Permalink
Added flask app files
Browse files Browse the repository at this point in the history
  • Loading branch information
aakashjhawar committed Dec 23, 2019
1 parent 0d04b54 commit 5f7f72d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
37 changes: 37 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import os
from flask import Flask, flash, request, redirect, url_for, render_template
from werkzeug.utils import secure_filename
import uuid


UPLOAD_FOLDER = 'tmp/'
ALLOWED_EXTENSIONS = set(['png', 'jpg', 'jpeg', 'gif'])

app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
app.secret_key = "super secret key"

def allowed_file(filename):
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS

@app.route('/', methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST':
# check if the post request has the file part
if 'file' not in request.files:
flash('No file part')
return redirect(request.url)
file = request.files['file']
# if user does not select file, browser also submit an empty part without filename
if file.filename == '':
flash('No selected file')
return redirect(request.url)
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
filename = str(uuid.uuid4()) + "." + filename.split('.')[1]
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
return redirect(url_for('upload_file', filename=filename))
return render_template("home.html")

if __name__ == '__main__':
app.run(debug=True)
7 changes: 7 additions & 0 deletions templates/home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!doctype html>
<title>SolveSudoku</title>
<h1>Upload new Image</h1>
<form method=post enctype=multipart/form-data>
<input type=file name=file>
<input type=submit value=Upload>
</form>

0 comments on commit 5f7f72d

Please sign in to comment.