I am learning the flask framework along with SQLAlchemy .
I am running this test script on a docker container without creating any templates for html pages which I am supposed to do or at least that what the documentation said.
from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.admin import Admin
from flask.ext.admin.contrib.sqla import ModelView
app = Flask(__name__)
db = SQLAlchemy(app)
db_uri = 'mysql://{u}:{p}@{h}/{s}?charset=utf8&use_unicode=1'
app.config['SQLALCHEMY_DATABASE_URI'] = db_uri.format(u='root',
p='matching',
h='127.0.0.1',
s='master_v2')
app.config['SQLALCHEMY_ECHO'] = True
db = SQLAlchemy(app)
class UserView(ModelView):
column_list = ('name', 'email')
column_searchable_list = ('name', 'email')
column_filters = ('name', 'email')
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(64), unique=True)
email = db.Column(db.String(128))
admin = Admin(app)
admin.add_view(UserView(User, db.session))
me = User(name='me', email='me@mail.com')
you = User(name='you', email='you@gmail.com')
db.create_all()
db.session.add(me)
db.session.add(you)
db.session.commit()
app.run()
And once I go to http://127.0.0.1:5000/admin/user/ it is actually returning an HTML page with a table containing my inserted values in the script. So How is this page loaded exactly ?
You need to go into the source to see what's happening. The ModelView class inherits from BaseModelView, which specifies specific templates to render for certain views. The default bootstrap2 templates are at here. The route that is called via /admin/user/
is here. You'll see that it renders self.list_template
.