Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from flask import Flask
- # Print a nice greeting
- def say_hello(username = "World"):
- return '<p>Hello %s!</p>\n' % username
- # Some bits of text for the page
- header_text = '''
- <html>\n<head> <title>EB Flask Test</title> </head>\n<body>'''
- instructions = '''
- <p><em>Hint</em>: This is a RESTful web service! Append a username
- to the URL (for example: <code>/Thelonious</code>) to say hello to
- someone specific.</p>\n'''
- home_link = '<p><a href="/">Back</a></p>\n'
- footer_text = '</body>\n</html>'
- # Elastic Beanstalk looks for an 'application' that is callable by default
- application = Flask(__name__)
- # Add a rule for the index page
- application.add_url_rule('/', 'index', (lambda: header_text +
- say_hello() + instructions + footer_text))
- # Add a rule when the page is accessed with a name appended to the site
- # URL
- application.add_url_rule('/<username>', 'hello', (lambda username:
- header_text + say_hello(username) + home_link + footer_text))
- # Run the application
- if __name__ == "__main__":
- # Setting debug to True enables debug output. This line should be
- # removed before deploying a production application.
- application.debug = True
- application.run(host="0.0.0.0")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement