am_dot_com

SW 2023-03-17

Mar 17th, 2023 (edited)
130
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 1 0
  1. # how_many_days_service.py
  2.  
  3. from flask import Flask, request, render_template
  4.  
  5. app = Flask(__name__)
  6.  
  7. NAME_IN_HTML_ELEMENT_FOR_USER_DATE =\
  8. "name_for_user_date"
  9.  
  10. @app.route("/")
  11. def respond_to_root():
  12. bFormFilled:bool =\
  13. NAME_IN_HTML_ELEMENT_FOR_USER_DATE \
  14. in \
  15. request.args
  16.  
  17. if (bFormFilled):
  18. the_date =\
  19. request.args[NAME_IN_HTML_ELEMENT_FOR_USER_DATE]
  20. r: str = f"<mark>Go the date {the_date}</mark>"
  21. return r
  22. else:
  23. return render_template("date_input.html")
  24. # def respond_to_root
  25.  
  26. @app.route("/<pDate>", methods=['GET'])
  27. def respond_to_date(pDate:str):
  28. r:str=f"<mark>Go the date {pDate}</mark>"
  29. return r
  30. # def respond_to_date
  31.  
  32. app.run(
  33. host="0.0.0.0",
  34. port=5556,
  35. debug=True
  36. )
  37.  
  38.  
  39.  
  40. ***************
  41.  
  42. <!DOCTYPE html>
  43. <html lang="en">
  44. <head>
  45. <meta charset="UTF-8">
  46. <title>Date Input</title>
  47. </head>
  48. <body>
  49. <form
  50. action="http://localhost:5556/"
  51. method="get"
  52. >
  53. <label for="id_the_user_date">Your date:</label>
  54. <input
  55. id="id_the_user_date"
  56. name="name_for_the_user_date"
  57. type="date"
  58. pattern="\d{4}-\d{2}-\d{2}"
  59. value="1969-06-21"
  60. >
  61. <input
  62. type="submit"
  63. value="submit date"
  64. >
  65. </form>
  66. </body>
  67. </html>
Advertisement
Add Comment
Please, Sign In to add comment