Advertisement
uopspop

Untitled

Dec 27th, 2018
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. from flask import Flask
  2.  
  3. # Print a nice greeting
  4. def say_hello(username = "World"):
  5. return '<p>Hello %s!</p>\n' % username
  6.  
  7. # Some bits of text for the page
  8. header_text = '''
  9. <html>\n<head> <title>EB Flask Test</title> </head>\n<body>'''
  10. instructions = '''
  11. <p><em>Hint</em>: This is a RESTful web service! Append a username
  12. to the URL (for example: <code>/Thelonious</code>) to say hello to
  13. someone specific.</p>\n'''
  14. home_link = '<p><a href="/">Back</a></p>\n'
  15. footer_text = '</body>\n</html>'
  16.  
  17. # Elastic Beanstalk looks for an 'application' that is callable by default
  18. application = Flask(__name__)
  19.  
  20. # Add a rule for the index page
  21. application.add_url_rule('/', 'index', (lambda: header_text +
  22. say_hello() + instructions + footer_text))
  23.  
  24. # Add a rule when the page is accessed with a name appended to the site
  25. # URL
  26. application.add_url_rule('/<username>', 'hello', (lambda username:
  27. header_text + say_hello(username) + home_link + footer_text))
  28.  
  29. # Run the application
  30. if __name__ == "__main__":
  31. # Setting debug to True enables debug output. This line should be
  32. # removed before deploying a production application.
  33. application.debug = True
  34. application.run(host="0.0.0.0")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement