Add documentation on how components are loaded.

This commit is contained in:
Emil Stenström 2021-02-05 23:59:42 +01:00
parent 63a63815e1
commit 189410cb0d

View file

@ -143,7 +143,9 @@ Now you need a Django template for your component. Feel free to define more vari
<div class="calendar-component">Today's date is <span>{{ date }}</span></div>
```
Finally, we use django-components to tie this together. We create a Component by inheriting from the Component class and specifying the context method. We also register the global component registry so that we easily can render it anywhere in our templates.
Finally, we use django-components to tie this together. Start by creating a file called `components.py` in any of your apps. It will be auto-detected and loaded by the app.
Inside this file we create a Component by inheriting from the Component class and specifying the context method. We also register the global component registry so that we easily can render it anywhere in our templates.
```python
from django_components import component
@ -255,6 +257,20 @@ NOTE: `{% csrf_token %}` tags need access to the top-level context, and they wil
Components can also access the outer context in their context methods by accessing the property `outer_context`.
# Configuring the library location
If you want to, you can configure the location where components are loaded. To do this, add a COMPONENTS variable to you settings.py with a list of libraries to look for. This allows you to build a structure of components that are independent from your apps.
```python
COMPONENTS = {
"libraries": [
"mysite.components.forms",
"mysite.components.buttons",
"mysite.components.cards",
]
}
```
# Running the tests
To quickly run the tests install the local dependencies by running