Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions calc_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from flask import Flask, render_template, request
import random
app = Flask(__name__)

@app.route("/")
def hello_form():
return render_template("calc_main.html")

@app.route("/calc", methods=["POST"])
def say_hello():
math_string = request.form['first'] + request.form['operators'] + \
request.form['second']

return render_template("calc.html", name=eval(math_string))

if __name__ == "__main__":
app.run(debug=True)
Binary file added templates/.DS_Store
Binary file not shown.
30 changes: 30 additions & 0 deletions templates/calc.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html>
<head>
<title>web calculator 0.1</title>
</head>
<body>
<form action="/calc" method="POST">
<p>
<h1>Calculator</h1>
</p>
<p>
<label for="calc-inputs">Please enter two numbers to calculate</label>
</p>
<p>
<input type="text" id="first_number" name="first" value={{name}}>
</p>
<select name="operators">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<p>
<input type="text" id="second_number" name="second" value="">
</p>
<input type="submit" value="submit">
</p>
</form>
</body>
</html>
30 changes: 30 additions & 0 deletions templates/calc_main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html>
<head>
<title>web calculator 0.1</title>
</head>
<body>
<form action="/calc" method="POST">
<p>
<h1>Calculator</h1>
</p>
<p>
<label for="calc-inputs">Please enter two numbers to calculate</label>
</p>
<p>
<input type="text" id="first_number" name="first" value="">
</p>
<select name="operators">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<p>
<input type="text" id="second_number" name="second" value="">
</p>
<input type="submit" value="submit">
</p>
</form>
</body>
</html>