Advertisement
Guest User

Untitled

a guest
May 20th, 2021
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. **NOTE FROM ULTRAPRIM: A few things needed to be debugged. For the frontend, I needed to change the https to http for the url
  2. For the backend, line 4 and 20 needed to be changed. I also added a "print(request.get_data()) on line 15.
  3. See final python code at EOF
  4.  
  5.  
  6. Write a html web application that takes the users name and password, then sends this data as a post request to localhost port 7000
  7.  
  8.  
  9.  
  10. <!DOCTYPE html>
  11.  
  12. <html>
  13.  
  14. <head>
  15.  
  16. <meta charset="utf-8">
  17.  
  18. <meta name="viewport" content="width=device-width, initial-scale=1">
  19.  
  20. <title>PHP Web Application</title>
  21.  
  22. </head>
  23.  
  24. <body>
  25.  
  26. <form method="post" action="https://localhost:7000/">
  27.  
  28. <input type="text" name="name" placeholder="John">
  29.  
  30. <input type="password" name="password" placeholder="password">
  31.  
  32.  
  33.  
  34. <input type="submit" value="Submit">
  35.  
  36. </form>
  37.  
  38. </body>
  39.  
  40. </html>
  41.  
  42. **END OF FIRST COMPLETION. This is when I gave instruction to write the backend
  43.  
  44. Now write python3 code to handle a post from this code.
  45.  
  46. from flask import Flask
  47.  
  48. app = Flask(__name__)
  49.  
  50. @app.route("/")
  51. def index():
  52.  
  53. name = request.args.get('name', '')
  54.  
  55. password = request.args.get('password', '')
  56.  
  57. print('Name: ' + name + ' Password: ' + password)
  58.  
  59. return 'Hello,
  60. '
  61.  
  62. if __name__ == '__main__':
  63.  
  64. app.run()
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82. ---------------------------
  83. DEBUGGED PYTHON CODE: **Computer did not supply this.
  84.  
  85. from flask import Flask
  86. from flask import request
  87.  
  88. app = Flask(__name__)
  89.  
  90. @app.route("/", methods=['GET', 'POST'])
  91. def index():
  92.  
  93. name = request.args.get('name', '')
  94.  
  95. password = request.args.get('password', '')
  96.  
  97. print('Name: ' + name + ' Password: ' + password)
  98.  
  99. print(request.get_data())
  100.  
  101. return 'Hello, '
  102.  
  103. if __name__ == '__main__':
  104.  
  105. app.run(port=7000)
  106.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement