Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from flask import Flask, render_template, request
- app = Flask(__name__)
- @app.route("/process_data", methods=['GET', 'POST'])
- def process_data():
- #get data from form request
- least_fav_class = request.form['lfc']
- flavor = request.form['flavor']
- lrs = request.form['state']
- favsport = request.form['sport']
- fvg = request.form['videogame']
- #save data record into a file
- #print(f"c={choco} s={straw} v={vanilla}")
- f = open("results.txt", "a")
- record = least_fav_class + '|' + flavor + '|' + lrs + '|' + favsport + '|' + fvg + '\n'
- f.write(record)
- f.close()
- #create HTML response page
- html = "<HTML><BODY>"
- html = html + "Thank you for your submission"
- html = html + '<br>Click <a href="/results">here</a> to see all results'
- html = html + "</BODY></HTML>"
- return(html)
- @app.route("/")
- def index():
- return render_template("index.html")
- @app.route("/results")
- def results():
- #read results file
- f = open("results.txt", "r")
- html = "<html><body>"
- html = html + "<table border=1>"
- html = html + "<tr>"
- html = html + "<th>Least Fav Class</th>"
- html = html + "<th>Ice Cream Flavor</th>"
- html = html + "<th>Preferred Vaca Destination</th>"
- html = html + "<th>Sport</th>"
- html = html + "<th>Video Game</th>"
- html = html + "</tr>"
- #build HTML table
- for line in f:
- cols = line.split('|')
- html = html + '<tr>'
- html = html + '<td>' + cols[0] + '</td>'
- html = html + '<td>' + cols[1] + '</td>'
- html = html + '<td>' + cols[2] + '</td>'
- html = html + '<td>' + cols[3] + '</td>'
- html = html + '<td>' + cols[4] + '</td>'
- html = html + '</tr>'
- html = html + '</table></body></html>'
- f.close()
- return(html)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement