Created
January 13, 2017 12:39
-
-
Save n1xx1/ab19f30f5d6ece87d30f9c8ccfb3615c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Calcola biglietto</title> | |
</head> | |
<body> | |
<form action="http://requestb.in/veydfzve" method="POST"> | |
Cognome: <input name="cognome" value="{{info.cognome if info.post else ''}}"><br> | |
Nome: <input name="nome" value="{{info.nome if info.post else ''}}"><br> | |
Numero Persone: <input name="num" value="{{info.num if info.post else ''}}"><br> | |
Settore: <select name="settore"> | |
<option value="0" {{'selected' if info.post and info.settore == 0 else ''}}>Prato</option> | |
<option value="1" {{'selected' if info.post and info.settore == 1 else ''}}>Tribuna</option> | |
<option value="2" {{'selected' if info.post and info.settore == 2 else ''}}>Tribuna Numerata</option> | |
</select><br> | |
Socio: <input type="checkbox" name="socio" value="1" {{'checked' if info.post and info.socio else ''}}><br> | |
<button type="submit">Invia</button> | |
</form> | |
<br><br> | |
{% if info.post %} | |
Costo biglietto: {{ info.costo }} | |
{% endif %} | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, request, redirect, render_template | |
app = Flask(__name__) | |
@app.route('/', methods=['GET', 'POST']) | |
def calcola_biglietto(): | |
info = {post: 0} | |
if request.method == 'POST': | |
info['cognome'] = request.form['cognome'] | |
info['nome'] = request.form['nome'] | |
info['num'] = int(request.form['num']) | |
info['settore'] = int(request.form['settore']) | |
info['socio'] = (request.form['socio'] == "1") | |
info['post'] = 1 | |
if info['settore'] == 0: | |
info['costo'] = 40 | |
elif info['settore'] == 1: | |
info['costo'] = 70 | |
elif info['settore'] == 2: | |
info['costo'] = 90 | |
else: | |
info['costo'] = 0 | |
if info['socio']: | |
info['costo'] = info['costo'] * 0.75 | |
render_template('index.html', info=info) | |
if __name__ == "__main__": | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment