Bootstrap 5 components for use with Django Cotton.
Project description
Django Cotton BS5
Bootstrap 5 components for Django Cotton - A comprehensive library of reusable, modular components.
Note: This project is currently a work in progress. Users are encouraged to request new components or features via the issue tracker.
Installation
pip install django-cotton-bs5
Add cotton_bs5 to your INSTALLED_APPS in settings.py:
INSTALLED_APPS = [
...
"django_cotton",
"cotton_bs5",
...
]
Available Components
The following Bootstrap 5 components are currently available as Django Cotton components:
- Alert (
<c-alert>) — Bootstrap alerts with variants, dismissible, slot/text support - Accordion (
<c-accordion>,<c-accordion.item>,<c-accordion.header>) — Collapsible accordion panels - Breadcrumbs (
<c-breadcrumbs>,<c-breadcrumbs.item>) — Navigation breadcrumbs - Button (
<c-button>) — Button/link with variants, outline, icon, slot/text - Button Group (
<c-button_group>) — Grouped buttons, vertical/size/label support - Card (
<c-card>,<c-card.body>,<c-card.title>) — Card container, body, and title - List Group (
<c-list_group>,<c-list_group.item>) — List group and items, horizontal/numbered/active/disabled - Modal (
<c-modal>,<c-modal.title>,<c-modal.body>) — Modal dialog, title, and body - Navbar (
<c-navbar>) — Responsive navigation bar with brand, expand, toggler - Progress (
<c-progress>) — Progress bar with value, min/max, variant, striped, animated, label - Spinner (
<c-spinner>) — Loading spinner, border/grow, size, variant, label - Table (
<c-table>) — Responsive table, striped, bordered, hover, small, variant, caption - Tabs (
<c-tabs>,<c-tabs.item>,<c-tabs.pane>) — Tab navigation and tab panes
More components are planned. Please request additional Bootstrap 5 components or features via the issue tracker.
Testing Components
This package provides four pytest fixtures for testing Django Cotton components:
cotton_render Fixture
Renders a component and returns the raw HTML as a string.
def test_alert_component(cotton_render):
html = cotton_render(
'cotton_bs5.alert',
message="Hello World",
variant="success"
)
assert 'alert-success' in html
assert 'Hello World' in html
cotton_render_soup Fixture
Renders a component and returns a BeautifulSoup parsed HTML object for easier DOM traversal and assertions.
def test_alert_component(cotton_render_soup):
soup = cotton_render_soup(
'cotton_bs5.alert',
message="Hello World",
variant="success"
)
alert_div = soup.find('div', class_='alert')
assert 'alert-success' in alert_div['class']
assert alert_div.get_text() == 'Hello World'
cotton_render_string Fixture
Compiles and renders template strings containing Cotton component syntax. Useful for testing multi-component markup and complex layouts inline without creating separate template files.
def test_button_inline(cotton_render_string):
html = cotton_render_string("<c-button variant='primary'>Click me</c-button>")
assert 'btn-primary' in html
def test_nested_components(cotton_render_string):
html = cotton_render_string(
"<c-ul><c-li text='first' /><c-li text='second' /></c-ul>"
)
assert 'first' in html
assert 'second' in html
cotton_render_string_soup Fixture
Combines cotton_render_string with BeautifulSoup parsing for easier DOM traversal and assertions on multi-component structures.
def test_nested_list(cotton_render_string_soup):
soup = cotton_render_string_soup(
"<c-ul><c-li text='first' /><c-li text='second' /></c-ul>"
)
items = soup.find_all('li')
assert len(items) == 2
assert items[0].get_text() == 'first'
def test_complex_layout(cotton_render_string_soup):
template = '''
<c-card>
<c-card.title>{{ title }}</c-card.title>
<c-card.body>
<c-button variant='primary'>{{ action }}</c-button>
</c-card.body>
</c-card>
'''
soup = cotton_render_string_soup(template, context={
'title': 'My Card',
'action': 'Click Here'
})
assert soup.find('h5').get_text() == 'My Card'
assert 'btn-primary' in soup.find('button')['class']
All fixtures automatically inject a request object, so you don't need to create one manually.
Contributing
This library follows django-cotton conventions and Bootstrap 5 standards. When adding new components:
- Use
<c-vars />for default values - Include proper accessibility attributes
- Support all relevant Bootstrap 5 options
- Maintain consistent naming conventions
- Test with various configurations
License
MIT License - see LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_cotton_bs5-0.8.0.tar.gz.
File metadata
- Download URL: django_cotton_bs5-0.8.0.tar.gz
- Upload date:
- Size: 93.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b1e3536db12a9ab2586f2addaa4a0a427b47de7f58799cc42f652234bf26e7a6
|
|
| MD5 |
4896f4cac6d74f69db8707d4059ef895
|
|
| BLAKE2b-256 |
567e54e1a96340b29d6887ad6c681e1085e5f787d11e4634b2342182adeb77e7
|
Provenance
The following attestation bundles were made for django_cotton_bs5-0.8.0.tar.gz:
Publisher:
on-release-main.yml on SamuelJennings/django-cotton-bs5
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_cotton_bs5-0.8.0.tar.gz -
Subject digest:
b1e3536db12a9ab2586f2addaa4a0a427b47de7f58799cc42f652234bf26e7a6 - Sigstore transparency entry: 947231443
- Sigstore integration time:
-
Permalink:
SamuelJennings/django-cotton-bs5@ae9055b7c3c2543559bf0cce127b782b89bd531a -
Branch / Tag:
refs/tags/v0.8.0 - Owner: https://github.com/SamuelJennings
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
on-release-main.yml@ae9055b7c3c2543559bf0cce127b782b89bd531a -
Trigger Event:
push
-
Statement type:
File details
Details for the file django_cotton_bs5-0.8.0-py3-none-any.whl.
File metadata
- Download URL: django_cotton_bs5-0.8.0-py3-none-any.whl
- Upload date:
- Size: 140.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
818bdb4eea8a1e80af9939aa4d273354f2df58db95e9415b56de02ea4f2a97ea
|
|
| MD5 |
63f3fa22399de6026341b88029ced1c7
|
|
| BLAKE2b-256 |
6434c9d4c2725e25b99d63cf28fc14a13593c9e6f6032488f0401f932321717c
|
Provenance
The following attestation bundles were made for django_cotton_bs5-0.8.0-py3-none-any.whl:
Publisher:
on-release-main.yml on SamuelJennings/django-cotton-bs5
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_cotton_bs5-0.8.0-py3-none-any.whl -
Subject digest:
818bdb4eea8a1e80af9939aa4d273354f2df58db95e9415b56de02ea4f2a97ea - Sigstore transparency entry: 947231446
- Sigstore integration time:
-
Permalink:
SamuelJennings/django-cotton-bs5@ae9055b7c3c2543559bf0cce127b782b89bd531a -
Branch / Tag:
refs/tags/v0.8.0 - Owner: https://github.com/SamuelJennings
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
on-release-main.yml@ae9055b7c3c2543559bf0cce127b782b89bd531a -
Trigger Event:
push
-
Statement type: