Skip to content

Hellrungj/flask-security-admin-example

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Example of combining Flask-Security and Flask-Admin
by Steve Saporta
April 15, 2014

Flask-Security provides a convenient way to add authentication and authorization to a Flask web app. Flask-Admin provides a convenient way to perform CRUD operations on database tables. This example combines Flask-Security and Flask-Admin so that authorized administrators can maintain the lists of users and roles that control access to the app.

You could easily generalize this app so that administrators could manage all sorts of database tables, not just users and roles.

This app also provides a basic example of the use of several underlying technologies that support Flask-Security and Flask-Admin.

Here are some helpful links:

To run this app, you'll need to install:

  • Python 3.3
  • Flask
  • Flask-Admin
  • Flask-Security
  • SQLAlchemy
  • A database system (PostgreSQL, SQLite, or another database system of your choice)
  • An empty database named "flask_example"

I personally ran it on Windows 7 with a PostgreSQL database, but you should be able to use the operating system and database system of your choice.

Comments throughout main.py explain what's going on.

Once you have the app running, you can view it in your browser (e.g. http://localhost:8080).

Some things to notice:

  • When you first visit the app's home page, you'll be prompted to log in, thanks to Flask-Security.
  • If you log in with username=someone@example.com and password=password, you'll have the "end-user" role.
  • If you log in with username=admin@example.com and password=password, you'll have the "admin" role.
  • Either role is permitted to access the home page.
  • Either role is permitted to access the /admin page. However, unless you have the "admin" role, you won't see the tabs for administration of users and roles on this page.
  • Only the admin role is permitted to access sub-pages of /admin page such as /admin/userview. Otherwise, you'll get a "forbidden" response.
  • Note that, when editing a user, the names of roles are automatically populated thanks to Flask-Admin.
  • You can add and edit users and roles. The resulting users will be able to log in (unless you set active=false) and, if they have the "admin" role, will be able to perform administration.

Enjoy!

About

Example of combining Flask-Security and Flask-Admin

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 96.2%
  • HTML 2.2%
  • Other 1.6%