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("/")
- def index():
- return render_template("index.html")
- @app.route("/collect", methods=['GET', 'POST'])
- def collect():
- #get the data into variables
- breakfast = request.form['bseq']
- favTV = request.form['tv']
- cp = request.form['chesspiece']
- favRest = request.form['restaurant']
- #save record into txt file
- f = open("results.txt", "a")
- record = breakfast + '|' + favTV + '|' + cp + '|' + favRest + '\n'
- f.write(record)
- f.close()
- html = "<HTML><BODY>"
- html = html + "Thank you for your submission."
- html = html + '<br><b>Click <a href="/results">here</a> to see all results'
- html = html + "</BODY></HTML>"
- return(html)
- @app.route("/results")
- def results():
- #open results file
- f = open("results.txt", "r")
- html = "<html><body>"
- html = html + "<table border=1>"
- html = html + "<tr>"
- html = html + "<th>Breakfast Seq</th>"
- html = html + "<th>TV Show</th>"
- html = html + "<th>Fav Chess Piece</th>"
- html = html + "<th>Restaurant</th>"
- html = html + "</tr>"
- #build HTML table rows from results file
- 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 + "</tr>"
- html = html + "</table></body></html>"
- #return HTML page to browser
- f.close()
- return(html)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement