Flask-Admin lets you build complicated interfaces by grouping individual views
together in classes: Each view that you see on the frontend, represents a
together in classes: Each web page you see on the frontend, represents a
method on a class that has explicitly been added to the interface.
These view classes are especially helpful when they are tied to particular
...
...
@@ -34,7 +34,7 @@ class for each of your models.
Initialization
--------------
The first step, is to initialise an empty admin interface on your Flask app::
To get started, the first step, is to initialise an empty admin interface on your Flask app::
from flask import Flask
from flask_admin import Admin
...
...
@@ -46,8 +46,10 @@ The first step, is to initialise an empty admin interface on your Flask app::
app.run()
Here, both the *name* and *template_mode* parameters are optional. If you start this application and navigate to `http://localhost:5000/admin/ <http://localhost:5000/admin/>`_,
you should see an empty "Home" page with a navigation bar on top, and the *name* that you specified.
Here, both the *name* and *template_mode* parameters are optional.
If you start this application and navigate to `http://localhost:5000/admin/ <http://localhost:5000/admin/>`_,
you should see an empty page with a navigation bar on top.
Adding Model Views
----------------------
...
...
@@ -72,10 +74,10 @@ Straight out of the box, this gives you a set of fully featured *CRUD* views for
There are many options available for customizing the display and functionality of these builtin view.
For more details on that, see :ref:`customising-builtin-views`.
Customising the index page
Adding Content to the Index Page
------------------------------------
The first thing you'll notice when you visit `http://localhost:5000/admin/ <http://localhost:5000/admin/>`_
is that it's just an empty page with a navigation menu. To add some content to this page, save the following text to a file in `my_app/templates/admin/index.html`::
is that it's just an empty page with a navigation menu. To add some content to this page, save the following text as `admin/index.html` in your project's `templates` directory::
{% extends 'admin/master.html' %}
...
...
@@ -83,7 +85,7 @@ is that it's just an empty page with a navigation menu. To add some content to t
<p>Hello world</p>
{% endblock %}
This will override the builtin index template, but still give you the builtin navigation menu. So, now you can add any content to the index page that makes sense for your app.
This will override the default index template, but still give you the navigation menu. So, now you can add any content to the index page that makes sense for your app.
****
...
...
@@ -114,16 +116,15 @@ How you implement the logic is up to you, but if you were to use a low-level lib
`Flask-Login <https://flask-login.readthedocs.org/>`_, then restricting access
could be as simple as::
class MyModelView(sqla.ModelView):
class BaseModelView(sqla.ModelView):
def is_accessible(self):
return login.current_user.is_authenticated()
However, you would still need to implement all of the relevant login /
registration views yourself.
However, you would still need to implement all of the relevant login,
registration and account management views yourself.
If you like this approach, then have a look at the example at