flask_admin.base
¶
Base View¶
-
expose
(url='/', methods=('GET', ))[源代码]¶ Use this decorator to expose views in your view classes.
参数: - url – Relative URL for the view
- methods – Allowed HTTP methods. By default only GET is allowed.
-
expose_plugview
(url='/')[源代码]¶ Decorator to expose Flask’s pluggable view classes (
flask.views.View
orflask.views.MethodView
).参数: url – Relative URL for the view 1.0.4 新版功能.
-
class
BaseView
(name=None, category=None, endpoint=None, url=None, static_folder=None, static_url_path=None, menu_class_name=None, menu_icon_type=None, menu_icon_value=None)[源代码]¶ Base administrative view.
Derive from this class to implement your administrative interface piece. For example:
from flask_admin import BaseView, expose class MyView(BaseView): @expose('/') def index(self): return 'Hello World!'
Icons can be added to the menu by using menu_icon_type and menu_icon_value. For example:
admin.add_view(MyView(name='My View', menu_icon_type='glyph', menu_icon_value='glyphicon-home'))
-
get_url
(endpoint, **kwargs)[源代码]¶ Generate URL for the endpoint. If you want to customize URL generation logic (persist some query string argument, for example), this is right place to do it.
参数: - endpoint – Flask endpoint name
- kwargs – Arguments for url_for
-
inaccessible_callback
(name, **kwargs)[源代码]¶ Handle the response to inaccessible views.
By default, it throw HTTP 403 error. Override this method to customize the behaviour.
-
is_accessible
()[源代码]¶ Override this method to add permission checks.
Flask-Admin does not make any assumptions about the authentication system used in your application, so it is up to you to implement it.
By default, it will allow access for everyone.
-
Default view¶
-
class
AdminIndexView
(name=None, category=None, endpoint=None, url=None, template='admin/index.html', menu_class_name=None, menu_icon_type=None, menu_icon_value=None)[源代码]¶ Default administrative interface index page when visiting the
/admin/
URL.It can be overridden by passing your own view class to the
Admin
constructor:class MyHomeView(AdminIndexView): @expose('/') def index(self): arg1 = 'Hello' return self.render('admin/myhome.html', arg1=arg1) admin = Admin(index_view=MyHomeView())
Also, you can change the root url from /admin to / with the following:
admin = Admin( app, index_view=AdminIndexView( name='Home', template='admin/myhome.html', url='/' ) )
Default values for the index page are:
- If a name is not provided, ‘Home’ will be used.
- If an endpoint is not provided, will default to
admin
- Default URL route is
/admin
. - Automatically associates with static folder.
- Default template is
admin/index.html
Admin¶
-
class
Admin
(app=None, name=None, url=None, subdomain=None, index_view=None, translations_path=None, endpoint=None, static_url_path=None, base_template=None, template_mode=None, category_icon_classes=None)[源代码]¶ Collection of the admin views. Also manages menu structure.
-
add_links
(*args)[源代码]¶ Add one or more links to the menu links collection.
Examples:
admin.add_links(link1) admin.add_links(link1, link2, link3, link4) admin.add_links(*my_list)
参数: args – Argument list including the links to add.
Add menu item to menu tree hierarchy.
参数: - menu_item – MenuItem class instance
- target_category – Target category name
-
add_sub_category
(name, parent_name)[源代码]¶ Add a category of a given name underneath the category with parent_name.
参数: - name – The name of the new menu category.
- parent_name – The name of a parent_name category
-
add_views
(*args)[源代码]¶ Add one or more views to the collection.
Examples:
admin.add_views(view1) admin.add_views(view1, view2, view3, view4) admin.add_views(*my_list)
参数: args – Argument list including the views to add.
-
init_app
(app, index_view=None, endpoint=None, url=None)[源代码]¶ Register all views with the Flask application.
参数: app – Flask application instance
Return the menu hierarchy.
Return menu links.
-