Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rails-inspire-django/django-viewcomponent
Build reusable components in Django, inspired by Rails ViewComponent
https://github.com/rails-inspire-django/django-viewcomponent
component django
Last synced: 8 days ago
JSON representation
Build reusable components in Django, inspired by Rails ViewComponent
- Host: GitHub
- URL: https://github.com/rails-inspire-django/django-viewcomponent
- Owner: rails-inspire-django
- Created: 2024-03-11T08:35:49.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2025-01-11T02:53:18.000Z (about 1 month ago)
- Last Synced: 2025-01-11T03:35:45.113Z (about 1 month ago)
- Topics: component, django
- Language: Python
- Homepage: https://django-viewcomponent.readthedocs.io/
- Size: 2.25 MB
- Stars: 57
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
- stars - rails-inspire-django/django-viewcomponent - Build reusable components in Django, inspired by Rails ViewComponent (Python)
- stars - rails-inspire-django/django-viewcomponent - Build reusable components in Django, inspired by Rails ViewComponent (Python)
README
# README
[](https://badge.fury.io/py/django-viewcomponent)
[](https://pypi.python.org/pypi/django-viewcomponent/)django-viewcomponent is a Django library that provides a way to create reusable components for your Django project.
It is inspired by Rails [ViewComponent](https://viewcomponent.org/), which built by GitHub.com
For more insights into the problem it addresses and its design philosophy, check out [this video by GitHub Staff member Joel Hawksley](https://youtu.be/QoetqsBCsbE?si=28PCFCD4N4CyfKY7&t=624)
## Use Component in Django Template
You can create components and use them in Django templates.

## Use Component in Python
Or you can create components and use them in pure Python code.

## Why use django-viewcomponent
### Single responsibility
django-viewcomponent can help developers to build reusable components from the Django templates, and make the templates more readable and maintainable.
### Testing
django-viewcomponent components are Python objects, so they can be **easily tested** without touching Django view and Django urls.
## Documentation
[Documentation](https://django-viewcomponent.readthedocs.io/en/latest/)
## FAQ
### django-viewcomponent vs django-components
1. **django-viewcomponent** is inspired by Rails [ViewComponent](https://viewcomponent.org/), focusing solely on encapsulating Django templates without concerning itself with other elements such as frontend assets or generating Django responses.
2. The `slot` field in **django-viewcomponent** can be invoked multiple times to pass collections.
3. In **django-viewcomponent**, slot fields are declared in the Python component file rather than in the template file, making the slot field more flexible and easier to maintain.
4. **django-viewcomponent** includes a preview feature that allows developers to easily create component previews.