Using Flask-SQLAlchemy within a class
- Kerem Ulutaş
- 2012-08-10 @ 23:37
In my previous post I asked for a way to use app instance in a class,
according to recommendations here is an example of what I have:
from flask import Flask
from flask.views import View
def __init__(self, template_name, methods=['GET']):
self.template_name = template_name
self.methods = methods
except Exception as e:
self.app = Flask(__name__)
myappinstance = MyApp()
app = myappinstance.app
Now, what I'm trying to accomplish is to use Flask-SQLAlchemy, I came
accross an example (
following the docs.
What is the best way to implement it with the code I have? As you can see,
I'm trying to follow an object oriented approach. I have been able to
create a class with the help of flask.views.View which I could bind URL's
by calling self.app.add_url_rule - but I couldn't do the same with
What would be the most appropriate and most Pythonic way?
Blog'umu okudunuz mu? http://www.ulutas.gen.tr
The box said "Requires Windows 95, NT, or better", so I installed Linux.