diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..246af523f --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "appService.defaultWebAppToDeploy": "/subscriptions/f57de2a6-3001-4498-93d4-fbc92e4ebf97/resourceGroups/appsvc_linux_centralus/providers/Microsoft.Web/sites/dblazrflsk", + "appService.deploySubpath": "." +} \ No newline at end of file diff --git a/app.py b/app.py index 9ab1ed730..638df8892 100644 --- a/app.py +++ b/app.py @@ -1,7 +1,11 @@ +import os from datetime import datetime from flask import Flask, render_template, request, redirect, url_for, send_from_directory +from werkzeug.utils import secure_filename +UPLOAD_FOLDER = 'uploads' +ALLOWED_EXTENSIONS = {'txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'} app = Flask(__name__) - +app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER @app.route('/') def index(): @@ -15,15 +19,39 @@ def favicon(): @app.route('/hello', methods=['POST']) def hello(): - name = request.form.get('name') + vorname = request.form.get('vorname') + nachname = request.form.get('nachname') - if name: - print('Request for hello page received with name=%s' % name) - return render_template('hello.html', name = name) + if vorname: + print('Request for hello page received with vorname=%s' % vorname) + return render_template('hello.html', vorname = vorname, nachname = nachname) else: print('Request for hello page received with no name or blank name -- redirecting') return redirect(url_for('index')) +@app.route('/selectfile') +def selectfile(): + print('Request for index page received') + return render_template('selectfile.html') + +def allowed_file(filename): + return '.' in filename and \ + filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS + +@app.route('/upload', methods=['POST']) +def upload(): + file = request.files['file'] + if file.filename == '': + print('No selected file') + return redirect(request.url) + if file and allowed_file(file.filename): + filename = secure_filename(file.filename) + file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) + return render_template('upload.html', filename=file.filename) + # return redirect(url_for('download_file', name=filename)) + else: + print('Request for hello page received with no file -- redirecting') + return redirect(url_for('index')) if __name__ == '__main__': app.run() \ No newline at end of file diff --git a/templates/hello.html b/templates/hello.html index c277e7740..67c3207aa 100644 --- a/templates/hello.html +++ b/templates/hello.html @@ -10,7 +10,7 @@
Azure Logo -

Hello {{name}}

+

Hello {{vorname}} {{nachname}}

It is nice to meet you!

diff --git a/templates/index.html b/templates/index.html index 9cdba30cd..58ef37c0f 100644 --- a/templates/index.html +++ b/templates/index.html @@ -14,13 +14,19 @@

Welcome to Azure

- + + + +
+ +
+
- -
-
+ +
+
diff --git a/templates/selectfile.html b/templates/selectfile.html new file mode 100644 index 000000000..9d9868da4 --- /dev/null +++ b/templates/selectfile.html @@ -0,0 +1,23 @@ + + + Hello Azure - Python Quickstart + + + + + +
+
+ Azure Logo +

Select a file for upload:

+ + +
+ +
+ + Back home +
+
+ + \ No newline at end of file diff --git a/templates/upload.html b/templates/upload.html new file mode 100644 index 000000000..3f7efa377 --- /dev/null +++ b/templates/upload.html @@ -0,0 +1,21 @@ + + + Hello Azure - Python Quickstart + + + + + +
+
+ Azure Logo + +

Thank you for uploading a file

+

+ {{filename}} +

+ Back home +
+
+ + \ No newline at end of file diff --git a/uploads/IMG_3327.jpg b/uploads/IMG_3327.jpg new file mode 100644 index 000000000..d49ec8e75 Binary files /dev/null and b/uploads/IMG_3327.jpg differ