-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflask_app.py
45 lines (36 loc) · 1.13 KB
/
flask_app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from flask import Flask, request, session, g, redirect, url_for, abort, \
render_template, flash, current_app
import json
class Person():
def __init__(self, name, email):
self.name = name
self.email = email
def say_hello(self):
return "Hello " + self.name + "!!"
app = Flask(__name__)
app.config.from_object(__name__)
#TODO
# @app.route('/', methods=['GET', 'POST'])
# def index(name=""):
# if request.method == 'POST':
# name = request.form["name"]
# # email = request.form["email"]
# # data = Person(name, email).say_hello()
# # return json.dumps({"data":data})
# return render_template('index.html', name=name)
#
#
# @app.route('/profile/<username>')
# def profile(username):
# return render_template('index.html')
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
name = request.form["name"]
email = request.form["email"]
data = Person(name, email).say_hello()
return json.dumps({"data":data})
else:
return render_template('index.html')
if __name__ == '__main__':
app.run(debug=True)