Add Lesson 5 Task 2
This commit is contained in:
parent
a6623ce880
commit
54fc772c83
2 changed files with 29 additions and 0 deletions
16
Lesson_5/Task 2/templates/index.html
Normal file
16
Lesson_5/Task 2/templates/index.html
Normal file
|
@ -0,0 +1,16 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>Calculator</title>
|
||||
</head>
|
||||
<body>
|
||||
<form action="">
|
||||
<label for="result">Result: </label><br>
|
||||
<input type="text" id="result" name="result" value="{{result|safe}}" disabled><br>
|
||||
<label for="operation">Operation: </label><br>
|
||||
<input type="text" id="operation" name="operation"><br>
|
||||
<input type="submit" value="Submit">
|
||||
</form>
|
||||
|
||||
</body>
|
||||
</html>
|
13
Lesson_5/Task 2/webserver.py
Normal file
13
Lesson_5/Task 2/webserver.py
Normal file
|
@ -0,0 +1,13 @@
|
|||
from flask import Flask, render_template, redirect, request
|
||||
from datetime import datetime
|
||||
|
||||
app = Flask("Calculator")
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
result = None
|
||||
if 'operation' in request.args:
|
||||
result = eval(request.args.get('operation'))
|
||||
return render_template("index.html", result=result)
|
||||
|
||||
app.run(port=8080)
|
Reference in a new issue