Skip to main content

A "GOV.UK Frontend" theme for Flask-Admin

This package is designed to make it trivial to re-skin a Flask-Admin extension to have a consistent look and feel to many UK Government services, by using layouts, components and patterns from the great GOV.UK Design System (among other x-gov resources).

Demo

Image

How to integrate with Flask-Admin

Make sure your Flask app's Jinja environment is configured to load templates from at least the sources listed below. Then initialise Flask-Admin and xgovuk-flask-admin appropriately, making sure to pass the X-GOV.UK Frontend Theme to Flask-Admin.

from flask import Flask
from jinja2 import PackageLoader, ChoiceLoader, PrefixLoader

from flask_admin import Admin
from xgovuk_flask_admin import XGovukFlaskAdmin
from xgovuk_flask_admin.theme import XGovukFrontendTheme

app = Flask(...)
app.jinja_options = {
  "loader": ChoiceLoader(
    [
      PrefixLoader({"govuk_frontend_jinja": PackageLoader("govuk_frontend_jinja")}),
      PrefixLoader({"govuk_frontend_wtf": PackageLoader("govuk_frontend_wtf")}),
      PackageLoader("xgovuk_flask_admin"),
    ]
  )
}

admin = Admin(app, theme=XGovukFrontendTheme())
xgovuk_flask_admin = XGovukFlaskAdmin(app)

Writing model views

All of your SQLAlchemy model fields should derive from xgovuk-flask-admin's XGovukModelView, not from Flask-Admin's sqla.ModelView.

To auto-generate CRUD pages for SQLAlchemy DB models, write sub-classes of XGovukModelView (which itself derives from Flask-Admin's sqla.ModelView):

from xgovuk_flask_admin import XGovukModelView

class UserModelView(XGovukModelView):
    page_size = 15
    can_create = True
    can_edit = True
    can_set_page_size = True
    page_size_options = [10, 15, 25, 50]

    form_args = {"email": {"validators": [Email()]}}

    column_filters = [
        "age",
        "job",
        "email",
        "created_at",
        "favourite_colour",
        "last_logged_in_at",
    ]

    column_searchable_list = ["email", "name"]

    can_export = True
    export_types = ["csv"]

    column_descriptions = {
        "age": "User's age in years",
        "email": "Email address for contacting the user",
        "created_at": "Date the user account was created",
        "last_logged_in_at": "Date and time of the user's last login",
    }

And then attach these model views to the Flask-Admin instance:

    flask_admin.add_view(UserModelView(User, db.session))

Writing custom views

Create a new Jinja2 template that extends from "admin/master.html" (which is a proxy for admin/base.html). Generally all you should need to implement is the action_panel block, like so:

{% extends "admin/master.html" %}

{% block action_panel %}
<div class="govuk-grid-row">
  <div class="govuk-grid-column-two-thirds">
    <h1 class="govuk-heading-l">Custom view</h1>
    <p class="govuk-body">This is a custom view where you can do whatever you want.</p>
  </div>
</div>
{% endblock %}

And then define a class for the view in Python:

from flask_admin import BaseView, expose

class CustomView(BaseView):
    @expose('/', methods=('GET',))
    def get(self):
        return self.render('custom_view.html')

And attach the view to your admin instance:

flask_admin.add_view(CustomView(name="Custom View", endpoint="custom"))

Recognition / attribution

This extension / theme has only been made possible by standing on a huge corpus of existing work across government, including but not limited to:

And, of course, Flask-Admin itself.

Compatibility

Python

xgovuk-flask-admin will aim to be compatible with all supported versions of Python released from 2025, but this package was put together in 2025 and I'm placing a lower bound of support on Python 3.12.

Flask-Admin

Not all features of Flask-Admin are currently supported, or likely to be supported in the future.

Feature Support status Notes
Nested service navigation menu items 🔮 Support Flask-Admin's "menu category" better, probably JS-only
Create new records ✅
List existing records ✅
Keyword search when listing records ✅
Apply filters when listing records ✅
Sort results ✅
Changing page size when listing results ✅
Custom page sizes ✅
Performing bulk actions on results ✅
Editing record fields when listing results 🤔 Flask-Admin allows you to edit columns from the "list model" view; I'm not sure we want/need to support for this XGovuk-Flask-Admin when taking into account design+accessibility factors
View existing records ✅
Edit existing records ✅
Delete existing records ✅
Edit relationships ✅
Optimise/support 'large' relationships 🔮 If a related table is large, performance will degrade rapidly because every related record is a choice in the select/dropdown menu. A future approach might be to dynamically load results from an API call
Edit date+datetime fields ✅
Edit one-to-one relationships ✅
Edit one-to-many relationships ✅
Standardised default GOV.UK error messages 🔮 It would be nice to have standard error messages for common validations, eg email format or dates
Show full related model forms inline 🤔 Flask-Admin allows rendering the full form of a related model inline of the main model (eg forms to edit posts by a user when editing a user). It might be nice to support this; some design thinking to do

Please raise an issue in this repository if you need functionality from Flask-Admin that isn't supported yet.

GOV.UK Frontend

xgovuk-flask-admin is packaged with compiled static assets that are served directly by the extension. This is a technical constraint applied because govuk-frontend-jinja and govuk-frontend-wtf are themselves designed for specific versions of GOV.UK Frontend.

Since xgovuk-flask-admin compiles assets from GOV.UK Frontend (and other x-gov frontend components), it will be locked to specific versions of govuk-frontend-jinja and govuk-frontend-wtf.

It may be possible to compile bundles for various versions of GOV.UK Frontend, in order to support various combinations of govuk-frontend-jinja and govuk-frontend-wtf in the future, but this is not currently planned. Please comment on https://github.com/samuelhwilliams/xgovuk-flask-admin/issues/1 if this would be useful.

The latest release of xgovuk-flask-admin will generally track the latest releases of GOV.UK Frontend, govuk-frontend-jinja, and govuk-frontend-wtf.

Package GOV.UK Frontend govuk-frontend-jinja govuk-frontend-wtf
>=0.1.0 5.13.0 3.9.0 3.2.0
< 0.1.0 5.12.0 3.8.0 3.2.0

xgovuk-flask-admin uses govuk-colour("purple") as its brand colour on the (somewhat unfounded/unresearched) belief that this isn't a colour used for branding in many places, so it's broadly "available". Given it will be unfamiliar, it visually signifies that you're in an unusual (read: privileged) interface. Because we pre-compile assets, we need to choose some colour, and I wanted to avoid black, GOV.UK blue, or common brands. Please comment on https://github. com/samuelhwilliams/xgovuk-flask-admin/issues/7 if customisation/extension is needed.

Because this theme uses common, well-tested components from across UK Government, it should be reasonably accessible out of the box and will generally be progressively enhanced (ie functional without javascript). However, some components used in xgovuk-flask-admin are not 'officially' fully supported or fully accessible, and xgovuk-flask-admin applies some customisation to styling and interactions on some components in order to work with Flask-Admin and provide a (hopefully) more usable design and experience.

Release files for xgovuk-flask-admin 0.1.9

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

Source distribution (sdist)

Source distribution for xgovuk-flask-admin 0.1.9
File Size Uploaded
xgovuk_flask_admin-0.1.9.tar.gz 451.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for xgovuk-flask-admin 0.1.9
File Interpreter ABI Platform
xgovuk_flask_admin-0.1.9-py3-none-any.whl Python 3 none any Details

Total release size: 910.4 kB

Release files / xgovuk_flask_admin-0.1.9.tar.gz

Download URL xgovuk_flask_admin-0.1.9.tar.gz
Size 451.3 kB
Tags Source
SHA-256 checksum
How to use checksums
8470b34f8a11ced867ef4054358f89bc029b15a7449adad5896f8d8c0407eadb
BLAKE2b-256 checksum
How to use checksums
a60147758ea7a6d3c3b6ebe517e3402f244ec56abf7420b3fe21fed25b1f02d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 7, 2026.

Transparency log

Release files / xgovuk_flask_admin-0.1.9-py3-none-any.whl

Download URL xgovuk_flask_admin-0.1.9-py3-none-any.whl
Size 459.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d84b786d510d3f98158e9e6cbbb9409165d0319cf825cde4411927336437d3e0
BLAKE2b-256 checksum
How to use checksums
267edf5a87f2b05e3d2f575755f6113fc5807b481d178593fb9cc113db639175
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 7, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.9 This release

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

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