External Exam Download Resources Web Applications Games Recycle Bin

inputs

GETinput.py

from flask import *
app = Flask(__name__)

loginPage = '''
<form action="/login" method="get">
  Enter your username and click Submit:<br>
  <input type="text" name="username"><br>
  <input type="submit" value="Submit">
</form>'''

@app.route("/login", methods=["GET"])
def login():
    return "Welcome " + request.args.get("username")

@app.route("/")
def main():
    return loginPage

app.run(debug=True)

POSTinput.py

from flask import *
app = Flask(__name__)

loginPage = '''
<form action="/login" method="post">
  Enter your username and click Submit:<br>
  <input type="text" name="username"><br>
  <input type="submit" value="Submit">
</form>'''

@app.route("/login", methods=["POST"])
def login():
    return "Welcome " + request.form["username"]

@app.route("/")
def main():
    return loginPage

app.run(debug=True)

POSTcalculator.py

from flask import *
app = Flask(__name__)

calculator = '''
<form action="/details" method="post">
  Number 1: <input type="text" name="num1"><br>
  Number 2: <input type="text" name="num2"><br>
  <input type="submit" value="Add">
</form>'''

@app.route("/details", methods=["POST"])
def feedback():
    num1 = int(request.form["num1"])
    num2 = int(request.form["num2"])
    answer = num1 + num2
    return str(answer)

@app.route("/")
def main():
    return calculator

app.run(debug=True)

POSTotherFormElements.py

from flask import *
app = Flask(__name__)

detailsPage = '''
<form action="/details" method="post">
  <input type="radio" name="transport" value="car" checked>Car<br>
  <input type="radio" name="transport" value="bus">Bus<br>
  <input type="checkbox" name="sport" value="cricket">Cricket<br>
  <input type="checkbox" name="sport" value="football" checked>Football<br>
  <select name="game">
    <option value="minecraft">Minecraft</option>
    <option value="fortnite">Fortnite</option>
  </select><br>
  <input type="submit" value="Submit">
</form>'''

@app.route("/details", methods=["POST"])
def feedback():
    HTML = ""
    HTML += "Transport: " + request.form["transport"] + "<br>"
    HTML += "Sport: " + request.form["sport"] + "<br>"
    HTML += "Game: " + request.form["game"]
    return HTML

@app.route("/")
def main():
    return detailsPage

app.run(debug=True)

redirection.py

from flask import *
app = Flask(__name__)

passcode = "abcd1234"

loginPage = '''
<form action="/login" method="post">
  Enter the password and click Submit:<br>
  <input type="text" name="password"><br>
  <input type="submit" value="Submit">
</form>'''

@app.route("/login", methods=["POST"])
def login():
    attempt = request.form["password"]
    if attempt == passcode:
        return redirect("/application")
    else:
        return redirect("/")

@app.route("/application")
def application():
    return "successful login"

@app.route("/")
def main():
    return loginPage

app.run(debug=True)