Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from flask import Flask, render_template, request
- amFlask = Flask(__name__)
- @amFlask.route("/confirmoResposta", methods=["GET", "POST"])
- def processarResposta():
- bGET = request.method=="GET"
- bPOST = request.method=="POST"
- if bGET:
- return(
- render_template(
- "resposta.html",
- #nome="Artur", #forçar valores
- #numero="9999" #forçar valores
- nome=request.args['nameNome'], #consulta de valores via get
- numero=request.args['nameNumero'] #consulta de valores via get
- )
- )
- elif bPOST:
- return (
- render_template(
- "resposta.html",
- nome=request.form['nameNome'],
- numero=request.form['nameNumero']
- )
- )
- @amFlask.route("/")
- def comoTratarRoot():
- return(
- #"<h1>Hello from root!</h1>"
- render_template(
- "questionario.html"
- )
- )
- #def comoTratarRoot
- @amFlask.route("/hello/<pName>")
- def comoTratarHello(pName):
- return(
- #f"<h1>Hello <mark>{pName}</mark>!</h1>"
- #"<h1>Hello <mark>%s</mark>!</h1>"%(pName)
- "<h1>Hello <mark>{}</mark>!</h1>".format(pName)
- )
- ****
- ***
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Questionário</title>
- </head>
- <body>
- <form>
- <label for="idNome">O seu nome:</label>
- <input
- type="text"
- id="idNome"
- name="nameNome"
- value="John"
- placeholder="Aqui o nome"
- >
- <br>
- <label for="idNumero">O seu número:</label>
- <input
- type="number"
- id="idNumero"
- name="nameNumero"
- value="1234"
- placeholder="Aqui o número"
- >
- <br>
- <input type="submit" value="Enviar resposta">
- </form>
- </body>
- </html>
- ***
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Resposta</title>
- </head>
- <body>
- <h1>Eis a resposta recebida:</h1>
- <ul>
- <li>Nome: {{ nome }}</li>
- <li>Numéro: {{ numero }}</li>
- </ul>
- </body>
- </html>
- *****
- from flask import Flask, render_template, request
- amFlask = Flask(__name__)
- @amFlask.route("/confirmoResposta")
- def processarResposta():
- return(
- render_template(
- "resposta.html",
- #nome="Artur",
- #numero="9999"
- nome=request.args['nameNome'], #get
- numero=request.args['nameNumero'] #get
- )
- )
- @amFlask.route("/")
- def comoTratarRoot():
- return(
- #"<h1>Hello from root!</h1>"
- render_template(
- "questionario.html"
- )
- )
- #def comoTratarRoot
- @amFlask.route("/hello/<pName>")
- def comoTratarHello(pName):
- return(
- #f"<h1>Hello <mark>{pName}</mark>!</h1>"
- #"<h1>Hello <mark>%s</mark>!</h1>"%(pName)
- "<h1>Hello <mark>{}</mark>!</h1>".format(pName)
- )
Add Comment
Please, Sign In to add comment