Skip to content

Instantly share code, notes, and snippets.

@matthewrobertbell
Last active December 14, 2015 23:49
Show Gist options
  • Save matthewrobertbell/5168688 to your computer and use it in GitHub Desktop.
Save matthewrobertbell/5168688 to your computer and use it in GitHub Desktop.
Nested classes, with autorouting, see https://github.com/mattseh/flask-classy
from flask import Flask, url_for
from flask.ext.classy import FlaskView
# we'll make a list to hold some quotes for our app
quotes = [
"A noble spirit embiggens the smallest man! ~ Jebediah Springfield",
"If there is a way to do it better... find it. ~ Thomas Edison",
"No one knows what he can do till he tries. ~ Publilius Syrus"
]
app = Flask(__name__)
class QuotesView(FlaskView):
def index(self):
return "<br>".join(quotes)
def arbritary(self):
return 'whatever'
class NestedView(FlaskView):
def index(self):
return 'I am nested'
class DoubleNestedView(FlaskView):
def index(self):
return 'I am double nested'
class PotatoView(FlaskView):
def index(self):
return 'I love potatoes'
class SubView(FlaskView):
def index(self):
return 'this is sub'
class SubSubView(FlaskView):
def index(self):
return 'this is subsub'
class SubView(FlaskView):
def index(self):
return 'Nested sub, same class names'
QuotesView.register(app)
SubView.register(app)
if __name__ == '__main__':
app.run(debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment