Commit f25d7f79 authored by Serge S. Koval's avatar Serge S. Koval

Template documentation, code clean up

parent c740b85e
......@@ -7,6 +7,7 @@ Flask-Admin is simple and extensible administrative interface framework for `Fla
:maxdepth: 2
quickstart
templates
model_guidelines
api/index
changelog
......
Working with templates
======================
Flask-Admin is built on top of standard Flask template management functionality.
If you're not familiar with Jinja2 templates, take a look `here <http://jinja.pocoo.org/docs/templates/>`_. Short summary:
1. You can derive from template
2. You can override template block(s)
3. When you override template block, you can render or not render parent block if you want to
Flask Core
----------
All Flask-Admin templates should derive from `admin/master.html`.
`admin/master.html` contains following blocks:
============= ========================================================================
head_meta Page metadata in the header
head_css Various CSS includes in the header
head Empty block in HTML head, in case you want to put something there
page_body Page layout
brand Logo in the menu bar
body Content (that's where your view will be displayed)
tail Empty area below content
============= ========================================================================
`admin/index.html` will be used display default `Home` admin page. By default it is empty.
Models
------
There are 3 main templates that are used to display models:
`admin/model/list.html` is list view template and contains following blocks:
================= ============================================
list_header Table header row
list_row Row block
list_row_actions Row action cell with edit/remove/etc buttons
================= ============================================
`admin/model/create.html` and `admin/model/edit.html` are used to display model creation editing forms respectively. They don't contain any custom
blocks and if you want to change something, you can do it using any of the blocks found in `admin/master.html`.
Customizing templates
---------------------
You can override any used template in your Flask application by creating template with same name and relative path in your main `templates` directory.
For example, if you want to override `admin/master.html`, create `admin/templates/admin/master.html` in your application and it will be used instead of
original `admin/master.html` found in Flask-Admin package.
If you don't want to replace template completely, you can create new template, derive it from existing template, override one or more blocks and
tell Flask-Admin to use it. For model view, there is `list_template` and related properties.
from flask import Flask, render_template
from flask import Flask
from flask.ext import admin
......@@ -37,9 +37,6 @@ if __name__ == '__main__':
admin.add_view(AnotherAdminView(category='Test'))
admin.init_app(app)
import pdb
pdb.set_trace()
# Start app
app.debug = True
app.run()
......@@ -182,12 +182,6 @@ class BaseView(object):
if self.name is None:
self.name = self._prettify_name(self.__class__.__name__)
# Figure out root_path
mod_name = self.__module__
mod = sys.modules[mod_name]
root_path = os.path.abspath(os.path.dirname(mod.__file__))
print mod_name, mod.__file__, root_path
# Create blueprint and register rules
self.blueprint = Blueprint(self.endpoint, __name__,
url_prefix=self.url,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment