CoolFace
Apppublic

Salysali/df-msdocs-python-flask-webapp-quickstart-14c3

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes
app.py33 linesDownload Raw Back to root
1import os
2
3from flask import (Flask, redirect, render_template, request,
4                   send_from_directory, url_for)
5
6app = Flask(__name__)
7
8
9@app.route('/')
10def index():
11   print('Request for index page received')
12   return render_template('index.html')
13
14@app.route('/favicon.ico')
15def favicon():
16    return send_from_directory(os.path.join(app.root_path, 'static'),
17                               'favicon.ico', mimetype='image/vnd.microsoft.icon')
18
19@app.route('/hello', methods=['POST'])
20def hello():
21   name = request.form.get('name')
22
23   if name:
24       print('Request for hello page received with name=%s' % name)
25       return render_template('hello.html', name = name)
26   else:
27       print('Request for hello page received with no name or blank name -- redirecting')
28       return redirect(url_for('index'))
29
30
31if __name__ == '__main__':
32   app.run(host="0.0.0.0", port=int(os.environ.get("PORT", 7860)))
33