Skip to content

Instantly share code, notes, and snippets.

@dplepage
Created March 12, 2012 19:26
Show Gist options
  • Save dplepage/2024129 to your computer and use it in GitHub Desktop.
Save dplepage/2024129 to your computer and use it in GitHub Desktop.
Subclassing Flask
import flask
class HelloApp(flask.Flask):
def __init__(self, import_name):
super(HelloApp, self).__init__(import_name)
self.route("/hello")(self.hello)
def hello(self):
return "Hello, world!"
class GoodbyeApp(flask.Flask):
def __init__(self, import_name):
super(GoodbyeApp, self).__init__(import_name)
self.route("/goodbye")(self.goodbye)
def goodbye(self):
return "Goodbye, world!"
class MyApp(HelloApp, GoodbyeApp):
def __init__(self, import_name):
super(MyApp, self).__init__(import_name)
self.route("/")(self.index)
def index(self):
return "<a href='{0}'>hello</a> <a href='{1}'>goodbye</a>".format(
flask.url_for("hello"), flask.url_for("goodbye"))
if __name__ == '__main__':
MyApp(__name__).run(debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment