am_dot_com

CN 2022-03-25

Mar 25th, 2022 (edited)
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. from flask import Flask, render_template, request
  2.  
  3. amFlask = Flask(__name__)
  4.  
  5. @amFlask.route("/confirmoResposta", methods=["GET", "POST"])
  6. def processarResposta():
  7. bGET = request.method=="GET"
  8. bPOST = request.method=="POST"
  9.  
  10. if bGET:
  11. return(
  12. render_template(
  13. "resposta.html",
  14. #nome="Artur", #forçar valores
  15. #numero="9999" #forçar valores
  16. nome=request.args['nameNome'], #consulta de valores via get
  17. numero=request.args['nameNumero'] #consulta de valores via get
  18. )
  19. )
  20. elif bPOST:
  21. return (
  22. render_template(
  23. "resposta.html",
  24. nome=request.form['nameNome'],
  25. numero=request.form['nameNumero']
  26. )
  27. )
  28.  
  29. @amFlask.route("/")
  30. def comoTratarRoot():
  31. return(
  32. #"<h1>Hello from root!</h1>"
  33. render_template(
  34. "questionario.html"
  35. )
  36. )
  37. #def comoTratarRoot
  38.  
  39. @amFlask.route("/hello/<pName>")
  40. def comoTratarHello(pName):
  41. return(
  42. #f"<h1>Hello <mark>{pName}</mark>!</h1>"
  43. #"<h1>Hello <mark>%s</mark>!</h1>"%(pName)
  44. "<h1>Hello <mark>{}</mark>!</h1>".format(pName)
  45. )
  46. ****
  47.  
  48. ***
  49.  
  50. <!DOCTYPE html>
  51. <html lang="en">
  52. <head>
  53. <meta charset="UTF-8">
  54. <title>Questionário</title>
  55. </head>
  56. <body>
  57. <form>
  58. <label for="idNome">O seu nome:</label>
  59. <input
  60. type="text"
  61. id="idNome"
  62. name="nameNome"
  63. value="John"
  64. placeholder="Aqui o nome"
  65. >
  66. <br>
  67. <label for="idNumero">O seu número:</label>
  68. <input
  69. type="number"
  70. id="idNumero"
  71. name="nameNumero"
  72. value="1234"
  73. placeholder="Aqui o número"
  74. >
  75. <br>
  76. <input type="submit" value="Enviar resposta">
  77. </form>
  78. </body>
  79. </html>
  80.  
  81. ***
  82.  
  83. <!DOCTYPE html>
  84. <html lang="en">
  85. <head>
  86. <meta charset="UTF-8">
  87. <title>Resposta</title>
  88. </head>
  89. <body>
  90. <h1>Eis a resposta recebida:</h1>
  91. <ul>
  92. <li>Nome: {{ nome }}</li>
  93. <li>Numéro: {{ numero }}</li>
  94. </ul>
  95. </body>
  96. </html>
  97.  
  98. *****
  99.  
  100. from flask import Flask, render_template, request
  101.  
  102. amFlask = Flask(__name__)
  103.  
  104. @amFlask.route("/confirmoResposta")
  105. def processarResposta():
  106. return(
  107. render_template(
  108. "resposta.html",
  109. #nome="Artur",
  110. #numero="9999"
  111. nome=request.args['nameNome'], #get
  112. numero=request.args['nameNumero'] #get
  113. )
  114. )
  115.  
  116. @amFlask.route("/")
  117. def comoTratarRoot():
  118. return(
  119. #"<h1>Hello from root!</h1>"
  120. render_template(
  121. "questionario.html"
  122. )
  123. )
  124. #def comoTratarRoot
  125.  
  126. @amFlask.route("/hello/<pName>")
  127. def comoTratarHello(pName):
  128. return(
  129. #f"<h1>Hello <mark>{pName}</mark>!</h1>"
  130. #"<h1>Hello <mark>%s</mark>!</h1>"%(pName)
  131. "<h1>Hello <mark>{}</mark>!</h1>".format(pName)
  132. )
  133.  
  134.  
  135.  
Add Comment
Please, Sign In to add comment