Skip to main content

flask_secure_admin

My little bundling of flask-admin and flask-security. Drawn heavily from the flask-admin example repo, also integrating sqlsoup because when I made it I didn't want to declare any models. Could be adapted to work with flask-sqlalchemy, surely.

Development

Uploading the package

# Update setup.py version number
python setup.py sdist
twine upload dist/flask_secure_admin-x.x.x.tar.gz # use the last version created

Usage

Run the following from a virtual environment:

pip install flask-secure-admin  # Or use pipenv

Add the following python to your project:

from flask_secure_admin import SecureAdminBlueprint
app.db = SQLSoup(os.environ['DATABASE_URI'])
app.register_blueprint(SecureAdminBlueprint(
    name='Your Project Name',
    url_prefix='secure-admin'))

Add sqlsoup models to your admin view by passing a list of their names as a third argument to SecureAdminBlueprint, and a list of view options for customization of these model views as a fourth argument:

app.register_blueprint(SecureAdminBlueprint(
    name='Your Project Name',
    url_prefix='secure-admin'
    models=['videos', 'captions', 'languages'],
    view_options=[
        dict(
            can_create=False,
            form_overrides=dict(filename=FileUploadField)
        )
    ], {}, {}))

See https://flask-admin.readthedocs.io/en/latest/api/mod_contrib_sqla/#flask_admin.contrib.sqla.ModelView and its parent class, https://flask-admin.readthedocs.io/en/latest/api/mod_model/#flask_admin.model.BaseModelView, for a list of all configuration options.

Last, run this to create necessary database tables in your database (PostgreSQL):

// Turns into, for example: psql yourdatabase < /Users/you/.local/share/virtualenvs/env-aP3G_9r-/lib/python3.7/site-packages/flask_secure_admin/create.sql
psql yourdatabase < $(dirname $(which pip))/../lib/$(python --version | sed 's/..$//' | sed 's/ //' | awk '{print tolower($0)}')/site-packages/flask_secure_admin/create.sql;    

This will create the tables: users, roles, & users_roles, so if you have any of those, this won't work. In that case, you're probably best off making sure you have each of the fields required on users and roles. See the create.sql file for reference.

At this point, you're set! Run your app, there should now be a protected '/admin' route.

Metadata

Release files for flask-secure-admin 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for flask-secure-admin 0.2.2
File Size Uploaded Provenance
flask_secure_admin-0.2.2.tar.gz 14.5 kB Without provenance Details

Release files / flask_secure_admin-0.2.2.tar.gz

Download URL flask_secure_admin-0.2.2.tar.gz
Size 14.5 kB
Tags Source
SHA-256 checksum
How to use checksums
30157a2160cfdf33d0af331d448c9e84afc55c5ed0fd0fd468fb8ae485feb83c
BLAKE2b-256 checksum
How to use checksums
21bfbcf930db8bfa2704af24bc9f99308e4aace80a538c16c7d9a3eee765fd78
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

Security for flask-secure-admin 0.2.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page