mirror of
https://github.com/django-components/django-components.git
synced 2025-08-04 14:28:18 +00:00
refactor: exclude underscored files from autodiscovery (#888)
This commit is contained in:
parent
1e4b556b4d
commit
203d29f511
6 changed files with 21 additions and 4 deletions
|
@ -15,7 +15,7 @@ class Calendar(Component):
|
|||
...
|
||||
```
|
||||
|
||||
But for the component to be registered, the code needs to be executed - the file needs to be imported as a module.
|
||||
But for the component to be registered, the code needs to be executed - and for that, the file needs to be imported as a module.
|
||||
|
||||
One way to do that is by importing all your components in `apps.py`:
|
||||
|
||||
|
@ -43,8 +43,9 @@ hook of the `apps.py` file.
|
|||
If you are using autodiscovery, keep a few points in mind:
|
||||
|
||||
- Avoid defining any logic on the module-level inside the `components` dir, that you would not want to run anyway.
|
||||
- Components inside the auto-imported files still need to be registered with [`@register`](django_components.component_registry.register)p
|
||||
- Components inside the auto-imported files still need to be registered with [`@register`](django_components.component_registry.register)
|
||||
- Auto-imported component files must be valid Python modules, they must use suffix `.py`, and module name should follow [PEP-8](https://peps.python.org/pep-0008/#package-and-module-names).
|
||||
- Subdirectories and files starting with an underscore `_` (except `__init__.py`) are ignored.
|
||||
|
||||
Autodiscovery can be disabled in the [settings](django_components.app_settings.ComponentsSettings.autodiscovery).
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue