public
Last active

Nested classes, with autorouting, see https://github.com/mattseh/flask-classy

  • Download Gist
gistfile1.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
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)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.