django-components 0.97__tar.gz → 0.100__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {django_components-0.97/src/django_components.egg-info → django_components-0.100}/PKG-INFO +216 -59
- {django_components-0.97 → django_components-0.100}/README.md +215 -58
- {django_components-0.97 → django_components-0.100}/pyproject.toml +1 -1
- {django_components-0.97 → django_components-0.100}/src/django_components/app_settings.py +55 -1
- {django_components-0.97 → django_components-0.100}/src/django_components/autodiscover.py +8 -16
- {django_components-0.97 → django_components-0.100}/src/django_components/component.py +9 -2
- {django_components-0.97 → django_components-0.100}/src/django_components/component_media.py +3 -3
- django_components-0.100/src/django_components/finders.py +154 -0
- django_components-0.100/src/django_components/template_loader.py +111 -0
- {django_components-0.97 → django_components-0.100}/src/django_components/utils.py +9 -0
- {django_components-0.97 → django_components-0.100/src/django_components.egg-info}/PKG-INFO +216 -59
- {django_components-0.97 → django_components-0.100}/src/django_components.egg-info/SOURCES.txt +2 -3
- {django_components-0.97 → django_components-0.100}/tests/test_component_as_view.py +22 -0
- {django_components-0.97 → django_components-0.100}/tests/test_component_media.py +4 -6
- django_components-0.100/tests/test_finders.py +210 -0
- {django_components-0.97 → django_components-0.100}/tests/test_registry.py +6 -2
- django_components-0.100/tests/test_template_loader.py +181 -0
- django_components-0.97/src/django_components/safer_staticfiles/apps.py +0 -22
- django_components-0.97/src/django_components/template_loader.py +0 -61
- django_components-0.97/src/django_components/templatetags/__init__.py +0 -0
- django_components-0.97/tests/test_safer_staticfiles.py +0 -103
- django_components-0.97/tests/test_template_loader.py +0 -76
- {django_components-0.97 → django_components-0.100}/LICENSE +0 -0
- {django_components-0.97 → django_components-0.100}/setup.cfg +0 -0
- {django_components-0.97 → django_components-0.100}/src/django_components/__init__.py +0 -0
- {django_components-0.97 → django_components-0.100}/src/django_components/apps.py +0 -0
- {django_components-0.97 → django_components-0.100}/src/django_components/attributes.py +0 -0
- {django_components-0.97 → django_components-0.100}/src/django_components/component_registry.py +0 -0
- {django_components-0.97 → django_components-0.100}/src/django_components/components/__init__.py +0 -0
- {django_components-0.97 → django_components-0.100}/src/django_components/components/dynamic.py +0 -0
- {django_components-0.97 → django_components-0.100}/src/django_components/context.py +0 -0
- {django_components-0.97 → django_components-0.100}/src/django_components/expression.py +0 -0
- {django_components-0.97 → django_components-0.100}/src/django_components/library.py +0 -0
- {django_components-0.97 → django_components-0.100}/src/django_components/logger.py +0 -0
- {django_components-0.97 → django_components-0.100}/src/django_components/management/__init__.py +0 -0
- {django_components-0.97 → django_components-0.100}/src/django_components/management/commands/__init__.py +0 -0
- {django_components-0.97 → django_components-0.100}/src/django_components/management/commands/startcomponent.py +0 -0
- {django_components-0.97 → django_components-0.100}/src/django_components/management/commands/upgradecomponent.py +0 -0
- {django_components-0.97 → django_components-0.100}/src/django_components/middleware.py +0 -0
- {django_components-0.97 → django_components-0.100}/src/django_components/node.py +0 -0
- {django_components-0.97 → django_components-0.100}/src/django_components/provide.py +0 -0
- {django_components-0.97 → django_components-0.100}/src/django_components/py.typed +0 -0
- {django_components-0.97 → django_components-0.100}/src/django_components/slots.py +0 -0
- {django_components-0.97 → django_components-0.100}/src/django_components/tag_formatter.py +0 -0
- {django_components-0.97 → django_components-0.100}/src/django_components/template.py +0 -0
- {django_components-0.97 → django_components-0.100}/src/django_components/template_parser.py +0 -0
- {django_components-0.97/src/django_components/safer_staticfiles → django_components-0.100/src/django_components/templatetags}/__init__.py +0 -0
- {django_components-0.97 → django_components-0.100}/src/django_components/templatetags/component_tags.py +0 -0
- {django_components-0.97 → django_components-0.100}/src/django_components/types.py +0 -0
- {django_components-0.97 → django_components-0.100}/src/django_components.egg-info/dependency_links.txt +0 -0
- {django_components-0.97 → django_components-0.100}/src/django_components.egg-info/requires.txt +0 -0
- {django_components-0.97 → django_components-0.100}/src/django_components.egg-info/top_level.txt +0 -0
- {django_components-0.97 → django_components-0.100}/tests/test_attributes.py +0 -0
- {django_components-0.97 → django_components-0.100}/tests/test_autodiscover.py +0 -0
- {django_components-0.97 → django_components-0.100}/tests/test_command_startcomponent.py +0 -0
- {django_components-0.97 → django_components-0.100}/tests/test_component.py +0 -0
- {django_components-0.97 → django_components-0.100}/tests/test_context.py +0 -0
- {django_components-0.97 → django_components-0.100}/tests/test_dependency_rendering.py +0 -0
- {django_components-0.97 → django_components-0.100}/tests/test_expression.py +0 -0
- {django_components-0.97 → django_components-0.100}/tests/test_settings.py +0 -0
- {django_components-0.97 → django_components-0.100}/tests/test_tag_formatter.py +0 -0
- {django_components-0.97 → django_components-0.100}/tests/test_template.py +0 -0
- {django_components-0.97 → django_components-0.100}/tests/test_template_parser.py +0 -0
- {django_components-0.97 → django_components-0.100}/tests/test_templatetags.py +0 -0
- {django_components-0.97 → django_components-0.100}/tests/test_templatetags_component.py +0 -0
- {django_components-0.97 → django_components-0.100}/tests/test_templatetags_provide.py +0 -0
- {django_components-0.97 → django_components-0.100}/tests/test_templatetags_slot_fill.py +0 -0
- {django_components-0.97 → django_components-0.100}/tests/test_templatetags_templating.py +0 -0
- {django_components-0.97 → django_components-0.100}/tests/test_utils.py +0 -0
- {django_components-0.97 → django_components-0.100}/tests/testutils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: django_components
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.100
|
|
4
4
|
Summary: A way to create simple reusable template components in Django.
|
|
5
5
|
Author-email: Emil Stenström <emil@emilstenstrom.se>
|
|
6
6
|
License: MIT
|
|
@@ -28,19 +28,24 @@ Requires-Dist: Django>=4.2
|
|
|
28
28
|
|
|
29
29
|
[**Docs (Work in progress)**](https://EmilStenstrom.github.io/django-components/latest/)
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
Django-components is a package that introduces component-based architecture to Django's server-side rendering. It aims to combine Django's templating system with the modularity seen in modern frontend frameworks.
|
|
32
32
|
|
|
33
33
|
## Features
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
1. 🧩 **Reusability:** Allows creation of self-contained, reusable UI elements.
|
|
36
|
+
2. 📦 **Encapsulation:** Each component can include its own HTML, CSS, and JavaScript.
|
|
37
|
+
3. 🚀 **Server-side rendering:** Components render on the server, improving initial load times and SEO.
|
|
38
|
+
4. 🐍 **Django integration:** Works within the Django ecosystem, using familiar concepts like template tags.
|
|
39
|
+
5. ⚡ **Asynchronous loading:** Components can render independently opening up for integration with JS frameworks like HTMX or AlpineJS.
|
|
36
40
|
|
|
37
|
-
|
|
38
|
-
- 📁 **Single file components**: Keep your Python, CSS, Javascript and HTML in one place (if you wish)
|
|
39
|
-
- 🎰 **Slots**: Define slots in your components to make them more flexible.
|
|
40
|
-
- 💻 **CLI**: A command line interface to help you create new components.
|
|
41
|
-
- 🚀 **Wide compatibility**: Works with [modern and LTS versions of Django](https://emilstenstrom.github.io/django-components/latest/user_guide/requirements_compatibility).
|
|
42
|
-
- **Load assets**: Automatically load the right CSS and Javascript files for your components, with [our middleware](https://emilstenstrom.github.io/django-components/latest/user_guide/creating_using_components/middleware).
|
|
41
|
+
Potential benefits:
|
|
43
42
|
|
|
43
|
+
- 🔄 Reduced code duplication
|
|
44
|
+
- 🛠️ Improved maintainability through modular design
|
|
45
|
+
- 🧠 Easier management of complex UIs
|
|
46
|
+
- 🤝 Potential for better collaboration between frontend and backend developers
|
|
47
|
+
|
|
48
|
+
Django-components can be particularly useful for larger Django projects that require a more structured approach to UI development, without necessitating a shift to a separate frontend framework.
|
|
44
49
|
|
|
45
50
|
## Summary
|
|
46
51
|
|
|
@@ -95,6 +100,17 @@ And this is what gets rendered (plus the CSS and Javascript you've specified):
|
|
|
95
100
|
|
|
96
101
|
## Release notes
|
|
97
102
|
|
|
103
|
+
🚨📢 **Version 0.100**
|
|
104
|
+
- BREAKING CHANGE:
|
|
105
|
+
- `django_components.safer_staticfiles` app was removed. It is no longer needed.
|
|
106
|
+
- Installation changes:
|
|
107
|
+
- Instead of defining component directories in `STATICFILES_DIRS`, set them to [`COMPONENTS.dirs`](#dirs).
|
|
108
|
+
- You now must define `STATICFILES_FINDERS`
|
|
109
|
+
- [See here how to migrate your settings.py](https://github.com/EmilStenstrom/django-components/blob/master/docs/migrating_from_safer_staticfiles.md)
|
|
110
|
+
- Beside the top-level `/components` directory, you can now define also app-level components dirs, e.g. `[app]/components`
|
|
111
|
+
(See [`COMPONENTS.app_dirs`](#app_dirs)).
|
|
112
|
+
- When you call `as_view()` on a component instance, that instance will be passed to `View.as_view()`
|
|
113
|
+
|
|
98
114
|
**Version 0.97**
|
|
99
115
|
- Fixed template caching. You can now also manually create cached templates with [`cached_template()`](#template_cache_size---tune-the-template-cache)
|
|
100
116
|
- The previously undocumented `get_template` was made private.
|
|
@@ -215,14 +231,25 @@ _You are advised to read this section before using django-components in producti
|
|
|
215
231
|
|
|
216
232
|
Components can be organized however you prefer.
|
|
217
233
|
That said, our prefered way is to keep the files of a component close together by bundling them in the same directory.
|
|
234
|
+
|
|
218
235
|
This means that files containing backend logic, such as Python modules and HTML templates, live in the same directory as static files, e.g. JS and CSS.
|
|
219
236
|
|
|
220
|
-
|
|
237
|
+
From v0.100 onwards, we keep component files (as defined by [`COMPONENTS.dirs`](#dirs) and [`COMPONENTS.app_dirs`](#app_dirs)) separate from the rest of the static
|
|
238
|
+
files (defined by `STATICFILES_DIRS`). That way, the Python and HTML files are NOT exposed by the server. Only the static JS, CSS, and [other common formats](#static_files_allowed).
|
|
239
|
+
|
|
240
|
+
> NOTE: If you need to expose different file formats, you can configure these with [`COMPONENTS.static_files_allowed`](#static_files_allowed)
|
|
241
|
+
and [`COMPONENTS.static_files_forbidden`](#static_files_forbidden).
|
|
242
|
+
|
|
243
|
+
<!-- # TODO_REMOVE_IN_V1 - Remove mentions of safer_staticfiles in V1 -->
|
|
244
|
+
#### Static files prior to v0.100
|
|
245
|
+
|
|
246
|
+
Prior to v0.100, if your were using _django.contrib.staticfiles_ to collect static files, no distinction was made between the different kinds of files.
|
|
247
|
+
|
|
221
248
|
As a result, your Python code and templates may inadvertently become available on your static file server.
|
|
222
249
|
You probably don't want this, as parts of your backend logic will be exposed, posing a **potential security vulnerability**.
|
|
223
250
|
|
|
224
|
-
|
|
225
|
-
It
|
|
251
|
+
From _v0.27_ until _v0.100_, django-components shipped with an additional installable app _django_components.**safer_staticfiles**_.
|
|
252
|
+
It was a drop-in replacement for _django.contrib.staticfiles_.
|
|
226
253
|
Its behavior is 100% identical except it ignores .py and .html files, meaning these will not end up on your static files server.
|
|
227
254
|
To use it, add it to INSTALLED_APPS and remove _django.contrib.staticfiles_.
|
|
228
255
|
|
|
@@ -254,11 +281,11 @@ For a step-by-step guide on deploying production server with static files,
|
|
|
254
281
|
|
|
255
282
|
## Installation
|
|
256
283
|
|
|
257
|
-
1. Install
|
|
284
|
+
1. Install `django_components` into your environment:
|
|
258
285
|
|
|
259
286
|
> `pip install django_components`
|
|
260
287
|
|
|
261
|
-
2.
|
|
288
|
+
2. Load `django_components` into Django by adding it into `INSTALLED_APPS` in settings.py:
|
|
262
289
|
|
|
263
290
|
```python
|
|
264
291
|
INSTALLED_APPS = [
|
|
@@ -267,13 +294,33 @@ For a step-by-step guide on deploying production server with static files,
|
|
|
267
294
|
]
|
|
268
295
|
```
|
|
269
296
|
|
|
270
|
-
3.
|
|
297
|
+
3. `BASE_DIR` setting is required. Ensure that it is defined in settings.py:
|
|
271
298
|
|
|
272
299
|
```py
|
|
273
300
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
|
274
301
|
```
|
|
275
302
|
|
|
276
|
-
4.
|
|
303
|
+
4. Add / modify [`COMPONENTS.dirs`](#dirs) and / or [`COMPONENTS.app_dirs`](#app_dirs) so django_components knows where to find component HTML, JS and CSS files:
|
|
304
|
+
|
|
305
|
+
```python
|
|
306
|
+
COMPONENTS = {
|
|
307
|
+
"dirs": [
|
|
308
|
+
...,
|
|
309
|
+
os.path.join(BASE_DIR, "components"),
|
|
310
|
+
],
|
|
311
|
+
}
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
If `COMPONENTS.dirs` is omitted, django-components will by default look for a top-level `/components` directory,
|
|
315
|
+
`{BASE_DIR}/components`.
|
|
316
|
+
|
|
317
|
+
Irrespective of `COMPONENTS.dirs`, django_components will also load components from app-level directories, e.g. `my-app/components/`.
|
|
318
|
+
The directories within apps are configured with [`COMPONENTS.app_dirs`](#app_dirs), and the default is `[app]/components`.
|
|
319
|
+
|
|
320
|
+
NOTE: The input to `COMPONENTS.dirs` is the same as for `STATICFILES_DIRS`, and the paths must be full paths. [See Django docs](https://docs.djangoproject.com/en/5.0/ref/settings/#staticfiles-dirs).
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
5. Next, to make Django load component HTML files as Django templates, modify `TEMPLATES` section of settings.py as follows:
|
|
277
324
|
|
|
278
325
|
- _Remove `'APP_DIRS': True,`_
|
|
279
326
|
- NOTE: Instead of APP_DIRS, for the same effect, we will use [`django.template.loaders.app_directories.Loader`](https://docs.djangoproject.com/en/5.1/ref/templates/api/#django.template.loaders.app_directories.Loader)
|
|
@@ -302,19 +349,18 @@ For a step-by-step guide on deploying production server with static files,
|
|
|
302
349
|
]
|
|
303
350
|
```
|
|
304
351
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
```python
|
|
308
|
-
STATICFILES_DIRS = [
|
|
309
|
-
...,
|
|
310
|
-
os.path.join(BASE_DIR, "components"),
|
|
311
|
-
]
|
|
312
|
-
```
|
|
352
|
+
6. Lastly, be able to serve the component JS and CSS files as static files, modify `STATICFILES_FINDERS` section of settings.py as follows:
|
|
313
353
|
|
|
314
|
-
|
|
315
|
-
|
|
354
|
+
```py
|
|
355
|
+
STATICFILES_FINDERS = [
|
|
356
|
+
# Default finders
|
|
357
|
+
"django.contrib.staticfiles.finders.FileSystemFinder",
|
|
358
|
+
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
|
|
359
|
+
# Django components
|
|
360
|
+
"django_components.finders.ComponentsFileSystemFinder",
|
|
361
|
+
]
|
|
362
|
+
```
|
|
316
363
|
|
|
317
|
-
NOTE: The paths in `STATICFILES_DIRS` must be full paths. [See Django docs](https://docs.djangoproject.com/en/5.0/ref/settings/#staticfiles-dirs).
|
|
318
364
|
|
|
319
365
|
### Optional
|
|
320
366
|
|
|
@@ -416,7 +462,7 @@ class Calendar(Component):
|
|
|
416
462
|
# Templates inside `[your apps]/components` dir and `[project root]/components` dir
|
|
417
463
|
# will be automatically found.
|
|
418
464
|
#
|
|
419
|
-
# `template_name` can be relative to dir where `calendar.py` is, or relative to
|
|
465
|
+
# `template_name` can be relative to dir where `calendar.py` is, or relative to COMPONENTS.dirs
|
|
420
466
|
template_name = "template.html"
|
|
421
467
|
# Or
|
|
422
468
|
def get_template_name(context):
|
|
@@ -428,7 +474,7 @@ class Calendar(Component):
|
|
|
428
474
|
"date": date,
|
|
429
475
|
}
|
|
430
476
|
|
|
431
|
-
# Both `css` and `js` can be relative to dir where `calendar.py` is, or relative to
|
|
477
|
+
# Both `css` and `js` can be relative to dir where `calendar.py` is, or relative to COMPONENTS.dirs
|
|
432
478
|
class Media:
|
|
433
479
|
css = "style.css"
|
|
434
480
|
js = "script.js"
|
|
@@ -1249,7 +1295,7 @@ class MyAppConfig(AppConfig):
|
|
|
1249
1295
|
|
|
1250
1296
|
However, there's a simpler way!
|
|
1251
1297
|
|
|
1252
|
-
By default, the Python files in the `
|
|
1298
|
+
By default, the Python files in the `COMPONENTS.dirs` directories (or app-level `[app]/components/`) are auto-imported in order to auto-register the components.
|
|
1253
1299
|
|
|
1254
1300
|
Autodiscovery occurs when Django is loaded, during the `ready` hook of the `apps.py` file.
|
|
1255
1301
|
|
|
@@ -1608,17 +1654,17 @@ Consider a component with slot(s). This component may do some processing on the
|
|
|
1608
1654
|
```py
|
|
1609
1655
|
@register("my_comp")
|
|
1610
1656
|
class MyComp(Component):
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1657
|
+
template = """
|
|
1658
|
+
<div>
|
|
1659
|
+
{% slot "content" default %}
|
|
1660
|
+
input: {{ input }}
|
|
1661
|
+
{% endslot %}
|
|
1662
|
+
</div>
|
|
1663
|
+
"""
|
|
1618
1664
|
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1665
|
+
def get_context_data(self, input):
|
|
1666
|
+
processed_input = do_something(input)
|
|
1667
|
+
return {"input": processed_input}
|
|
1622
1668
|
```
|
|
1623
1669
|
|
|
1624
1670
|
You may want to design a component so that users of your component can still access the `input` variable, so they don't have to recompute it.
|
|
@@ -1637,17 +1683,17 @@ To pass the data to the `slot` tag, simply pass them as keyword attributes (`key
|
|
|
1637
1683
|
```py
|
|
1638
1684
|
@register("my_comp")
|
|
1639
1685
|
class MyComp(Component):
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1686
|
+
template = """
|
|
1687
|
+
<div>
|
|
1688
|
+
{% slot "content" default input=input %}
|
|
1689
|
+
input: {{ input }}
|
|
1690
|
+
{% endslot %}
|
|
1691
|
+
</div>
|
|
1692
|
+
"""
|
|
1693
|
+
|
|
1694
|
+
def get_context_data(self, input):
|
|
1695
|
+
processed_input = do_something(input)
|
|
1696
|
+
return {
|
|
1651
1697
|
"input": processed_input,
|
|
1652
1698
|
}
|
|
1653
1699
|
```
|
|
@@ -1981,13 +2027,13 @@ Assuming that:
|
|
|
1981
2027
|
class_from_var = "from-var"
|
|
1982
2028
|
|
|
1983
2029
|
attrs = {
|
|
1984
|
-
|
|
1985
|
-
|
|
2030
|
+
"class": "from-attrs",
|
|
2031
|
+
"type": "submit",
|
|
1986
2032
|
}
|
|
1987
2033
|
|
|
1988
2034
|
defaults = {
|
|
1989
|
-
|
|
1990
|
-
|
|
2035
|
+
"class": "from-defaults",
|
|
2036
|
+
"role": "button",
|
|
1991
2037
|
}
|
|
1992
2038
|
```
|
|
1993
2039
|
|
|
@@ -2892,9 +2938,9 @@ class Calendar(Component):
|
|
|
2892
2938
|
|
|
2893
2939
|
In the example above, the files are defined relative to the directory where `component.py` is.
|
|
2894
2940
|
|
|
2895
|
-
Alternatively, you can specify the file paths relative to the directories set in `
|
|
2941
|
+
Alternatively, you can specify the file paths relative to the directories set in `COMPONENTS.dirs` or `COMPONENTS.app_dirs`.
|
|
2896
2942
|
|
|
2897
|
-
Assuming that `
|
|
2943
|
+
Assuming that `COMPONENTS.dirs` contains path `[project root]/components`, we can rewrite the example as:
|
|
2898
2944
|
|
|
2899
2945
|
```py
|
|
2900
2946
|
# In a file [project root]/components/calendar/calendar.py
|
|
@@ -2990,7 +3036,7 @@ In the example [above](#supported-types-for-file-paths), you could see that when
|
|
|
2990
3036
|
|
|
2991
3037
|
This is an extension of Django's [Paths as objects](https://docs.djangoproject.com/en/5.0/topics/forms/media/#paths-as-objects) feature, where "safe" strings are taken as is, and accessed only at render time.
|
|
2992
3038
|
|
|
2993
|
-
Because of that, the paths defined as "safe" strings are NEVER resolved, neither relative to component's directory, nor relative to `
|
|
3039
|
+
Because of that, the paths defined as "safe" strings are NEVER resolved, neither relative to component's directory, nor relative to `COMPONENTS.dirs`.
|
|
2994
3040
|
|
|
2995
3041
|
"Safe" strings can be used to lazily resolve a path, or to customize the `<script>` or `<link>` tag for individual paths:
|
|
2996
3042
|
|
|
@@ -3110,10 +3156,27 @@ Here's overview of all available settings and their defaults:
|
|
|
3110
3156
|
COMPONENTS = {
|
|
3111
3157
|
"autodiscover": True,
|
|
3112
3158
|
"context_behavior": "django", # "django" | "isolated"
|
|
3159
|
+
"dirs": [BASE_DIR / "components"], # Root-level "components" dirs, e.g. `/path/to/proj/components/`
|
|
3160
|
+
"app_dirs": ["components"], # App-level "components" dirs, e.g. `[app]/components/`
|
|
3113
3161
|
"dynamic_component_name": "dynamic",
|
|
3114
3162
|
"libraries": [], # ["mysite.components.forms", ...]
|
|
3115
3163
|
"multiline_tags": True,
|
|
3116
3164
|
"reload_on_template_change": False,
|
|
3165
|
+
"static_files_allowed": [
|
|
3166
|
+
".css",
|
|
3167
|
+
".js",
|
|
3168
|
+
# Images
|
|
3169
|
+
".apng", ".png", ".avif", ".gif", ".jpg",
|
|
3170
|
+
".jpeg", ".jfif", ".pjpeg", ".pjp", ".svg",
|
|
3171
|
+
".webp", ".bmp", ".ico", ".cur", ".tif", ".tiff",
|
|
3172
|
+
# Fonts
|
|
3173
|
+
".eot", ".ttf", ".woff", ".otf", ".svg",
|
|
3174
|
+
],
|
|
3175
|
+
"static_files_forbidden": [
|
|
3176
|
+
".html", ".django", ".dj", ".tpl",
|
|
3177
|
+
# Python files
|
|
3178
|
+
".py", ".pyc",
|
|
3179
|
+
],
|
|
3117
3180
|
"tag_formatter": "django_components.component_formatter",
|
|
3118
3181
|
"template_cache_size": 128,
|
|
3119
3182
|
}
|
|
@@ -3171,6 +3234,46 @@ COMPONENTS = {
|
|
|
3171
3234
|
}
|
|
3172
3235
|
```
|
|
3173
3236
|
|
|
3237
|
+
### `dirs`
|
|
3238
|
+
|
|
3239
|
+
Specify the directories that contain your components.
|
|
3240
|
+
|
|
3241
|
+
Directories must be full paths, same as with STATICFILES_DIRS.
|
|
3242
|
+
|
|
3243
|
+
These locations are searched during autodiscovery, or when you define HTML, JS, or CSS as
|
|
3244
|
+
a separate file.
|
|
3245
|
+
|
|
3246
|
+
```py
|
|
3247
|
+
COMPONENTS = {
|
|
3248
|
+
"dirs": [BASE_DIR / "components"],
|
|
3249
|
+
}
|
|
3250
|
+
```
|
|
3251
|
+
|
|
3252
|
+
### `app_dirs`
|
|
3253
|
+
|
|
3254
|
+
Specify the app-level directories that contain your components.
|
|
3255
|
+
|
|
3256
|
+
Directories must be relative to app, e.g.:
|
|
3257
|
+
|
|
3258
|
+
```py
|
|
3259
|
+
COMPONENTS = {
|
|
3260
|
+
"app_dirs": ["my_comps"], # To search for [app]/my_comps
|
|
3261
|
+
}
|
|
3262
|
+
```
|
|
3263
|
+
|
|
3264
|
+
These locations are searched during autodiscovery, or when you define HTML, JS, or CSS as
|
|
3265
|
+
a separate file.
|
|
3266
|
+
|
|
3267
|
+
Each app will be searched for these directories.
|
|
3268
|
+
|
|
3269
|
+
Set to empty list to disable app-level components:
|
|
3270
|
+
|
|
3271
|
+
```py
|
|
3272
|
+
COMPONENTS = {
|
|
3273
|
+
"app_dirs": [],
|
|
3274
|
+
}
|
|
3275
|
+
```
|
|
3276
|
+
|
|
3174
3277
|
### `dynamic_component_name`
|
|
3175
3278
|
|
|
3176
3279
|
By default, the dynamic component is registered under the name `"dynamic"`. In case of a conflict, use this setting to change the name used for the dynamic components.
|
|
@@ -3191,6 +3294,60 @@ COMPONENTS = {
|
|
|
3191
3294
|
}
|
|
3192
3295
|
```
|
|
3193
3296
|
|
|
3297
|
+
### `static_files_allowed`
|
|
3298
|
+
|
|
3299
|
+
A list of regex patterns (as strings) that define which files within `COMPONENTS.dirs` and `COMPONENTS.app_dirs`
|
|
3300
|
+
are treated as static files.
|
|
3301
|
+
|
|
3302
|
+
If a file is matched against any of the patterns, it's considered a static file. Such files are collected
|
|
3303
|
+
when running `collectstatic`, and can be accessed under the static file endpoint.
|
|
3304
|
+
|
|
3305
|
+
You can also pass in compiled regexes (`re.Pattern`) for more advanced patterns.
|
|
3306
|
+
|
|
3307
|
+
By default, JS, CSS, and common image and font file formats are considered static files:
|
|
3308
|
+
|
|
3309
|
+
```python
|
|
3310
|
+
COMPONENTS = {
|
|
3311
|
+
"static_files_allowed": [
|
|
3312
|
+
"css",
|
|
3313
|
+
"js",
|
|
3314
|
+
# Images
|
|
3315
|
+
".apng", ".png",
|
|
3316
|
+
".avif",
|
|
3317
|
+
".gif",
|
|
3318
|
+
".jpg", ".jpeg", ".jfif", ".pjpeg", ".pjp", # JPEG
|
|
3319
|
+
".svg",
|
|
3320
|
+
".webp", ".bmp",
|
|
3321
|
+
".ico", ".cur", # ICO
|
|
3322
|
+
".tif", ".tiff",
|
|
3323
|
+
# Fonts
|
|
3324
|
+
".eot", ".ttf", ".woff", ".otf", ".svg",
|
|
3325
|
+
],
|
|
3326
|
+
}
|
|
3327
|
+
```
|
|
3328
|
+
|
|
3329
|
+
### `static_files_forbidden`
|
|
3330
|
+
|
|
3331
|
+
A list of suffixes that define which files within `COMPONENTS.dirs` and `COMPONENTS.app_dirs`
|
|
3332
|
+
will NEVER be treated as static files.
|
|
3333
|
+
|
|
3334
|
+
If a file is matched against any of the patterns, it will never be considered a static file, even if the file matches
|
|
3335
|
+
a pattern in [`COMPONENTS.static_files_allowed`](#static_files_allowed).
|
|
3336
|
+
|
|
3337
|
+
Use this setting together with `COMPONENTS.static_files_allowed` for a fine control over what files will be exposed.
|
|
3338
|
+
|
|
3339
|
+
You can also pass in compiled regexes (`re.Pattern`) for more advanced patterns.
|
|
3340
|
+
|
|
3341
|
+
By default, any HTML and Python are considered NOT static files:
|
|
3342
|
+
|
|
3343
|
+
```python
|
|
3344
|
+
COMPONENTS = {
|
|
3345
|
+
"static_files_forbidden": [
|
|
3346
|
+
".html", ".django", ".dj", ".tpl", ".py", ".pyc",
|
|
3347
|
+
],
|
|
3348
|
+
}
|
|
3349
|
+
```
|
|
3350
|
+
|
|
3194
3351
|
### `template_cache_size` - Tune the template cache
|
|
3195
3352
|
|
|
3196
3353
|
Each time a template is rendered it is cached to a global in-memory cache (using Python's `lru_cache` decorator). This speeds up the next render of the component. As the same component is often used many times on the same page, these savings add up.
|
|
@@ -3619,7 +3776,7 @@ You can publish and share your components for others to use. Here are the steps
|
|
|
3619
3776
|
|
|
3620
3777
|
4. Import the components in `apps.py`
|
|
3621
3778
|
|
|
3622
|
-
Normally, users rely on [autodiscovery](#autodiscovery) and `
|
|
3779
|
+
Normally, users rely on [autodiscovery](#autodiscovery) and `COMPONENTS.dirs` to load the component files.
|
|
3623
3780
|
|
|
3624
3781
|
Since you, as the library author, are not in control of the file system, it is recommended to load the components manually.
|
|
3625
3782
|
|