mirror of
https://github.com/django-components/django-components.git
synced 2025-09-27 07:59:08 +00:00
Add documentation on how components are loaded.
This commit is contained in:
parent
63a63815e1
commit
189410cb0d
1 changed files with 17 additions and 1 deletions
18
README.md
18
README.md
|
@ -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>
|
<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
|
```python
|
||||||
from django_components import component
|
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`.
|
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
|
# Running the tests
|
||||||
|
|
||||||
To quickly run the tests install the local dependencies by running
|
To quickly run the tests install the local dependencies by running
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue