insroduction.txt 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. :tocdepth: 2
  2. Introduction To Flask-Admin
  3. ###########################
  4. Getting Started
  5. ===============
  6. ****
  7. Initialization
  8. --------------
  9. The first step is to initialize an empty admin interface for your Flask app::
  10. from flask import Flask
  11. from flask_admin import Admin
  12. app = Flask(__name__)
  13. admin = Admin(app, name='microblog', template_mode='bootstrap3')
  14. # Add administrative views here
  15. app.run()
  16. Here, both the *name* and *template_mode* parameters are optional. Alternatively,
  17. you could use the :meth:`~flask_admin.base.Admin.init_app` method.
  18. If you start this application and navigate to `http://localhost:5000/admin/ <http://localhost:5000/admin/>`_,
  19. you should see an empty page with a navigation bar on top.
  20. Adding Model Views
  21. ------------------
  22. Model views allow you to add a dedicated set of admin pages for managing any model in your database. Do this by creating
  23. instances of the *ModelView* class, which you can import from one of Flask-Admin's built-in ORM backends. An example
  24. is the SQLAlchemy backend, which you can use as follows::
  25. from flask_admin.contrib.sqla import ModelView
  26. # Flask and Flask-SQLAlchemy initialization here
  27. admin = Admin(app, name='