Guest User

Untitled

a guest
Jan 18th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. from flask import Flask,jsonify,request,url_for,redirect
  2.  
  3. app = Flask(__name__)
  4.  
  5.  
  6. @app.route('/home',methods=["POST","GET"])
  7. def home(name,lastname):
  8. if request.method == "GET":
  9. return '''
  10. <form method="POST" action="/home">
  11. <input type="text" name=name">
  12. <input type="text" lastname=lastname">
  13. <button type="submit"></button>
  14. '''
  15. else:
  16. return redirect(url_for('accept_data'))
  17.  
  18. @app.route('/accept_data')
  19. def accept_data():
  20. name = request.args.get("name")
  21. lastname = request.args.get("lastname")
  22. if name and lastname:
  23. return "<h1>Your first name is {} and lastname is {}</h1>".format(name,lastname)
  24. else:
  25. return "<h1>You dont have a first and lastname </h1>"
  26.  
  27.  
  28. if __name__ == "__main__":
  29. app.run(debug=True)
Add Comment
Please, Sign In to add comment