Deployed f100cc18 to dev with MkDocs 1.6.1 and mike 2.1.3

This commit is contained in:
github-actions 2025-09-10 12:08:25 +00:00
parent d7c0bf40c5
commit b4b5f972ff
79 changed files with 547 additions and 725 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -120,34 +120,34 @@
<a id=__codelineno-0-5 name=__codelineno-0-5 href=#__codelineno-0-5></a> <span class=c1># Add a new attribute to the Component class</span> <a id=__codelineno-0-5 name=__codelineno-0-5 href=#__codelineno-0-5></a> <span class=c1># Add a new attribute to the Component class</span>
<a id=__codelineno-0-6 name=__codelineno-0-6 href=#__codelineno-0-6></a> <span class=n>ctx</span><span class=o>.</span><span class=n>component_cls</span><span class=o>.</span><span class=n>my_attr</span> <span class=o>=</span> <span class=s2>&quot;my_value&quot;</span> <a id=__codelineno-0-6 name=__codelineno-0-6 href=#__codelineno-0-6></a> <span class=n>ctx</span><span class=o>.</span><span class=n>component_cls</span><span class=o>.</span><span class=n>my_attr</span> <span class=o>=</span> <span class=s2>&quot;my_value&quot;</span>
</code></pre></div> </div> </div><p><strong>Available data:</strong></p> <table> <thead> <tr> <th>name</th> <th>type</th> <th>description</th> </tr> </thead> <tbody> <tr> <td><code>component_cls</code></td> <td><a href=../api#django_components.Component><code>Type[Component]</code></a></td> <td>The created Component class</td> </tr> </tbody> </table> <div class="doc doc-object doc-function"> <h3 id=django_components.extension.ComponentExtension.on_component_class_deleted class="doc doc-heading"> <span class="doc doc-object-name doc-function-name">on_component_class_deleted</span> <a href=#django_components.extension.ComponentExtension.on_component_class_deleted class=headerlink title="Permanent link">¤</a></h3> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=nf>on_component_class_deleted</span><span class=p>(</span><span class=n>ctx</span><span class=p>:</span> <span class=n><a class="autorefs autorefs-internal" title=" OnComponentClassDeletedContext (django_components.extension.OnComponentClassDeletedContext)" href=#django_components.extension.OnComponentClassDeletedContext>OnComponentClassDeletedContext</a></span><span class=p>)</span> <span class=o>-&gt;</span> <span class=kc>None</span> </code></pre></div> </div> </div><p><strong>Available data:</strong></p> <table> <thead> <tr> <th>name</th> <th>type</th> <th>description</th> </tr> </thead> <tbody> <tr> <td><code>component_cls</code></td> <td><a href=../api#django_components.Component><code>Type[Component]</code></a></td> <td>The created Component class</td> </tr> </tbody> </table> <div class="doc doc-object doc-function"> <h3 id=django_components.extension.ComponentExtension.on_component_class_deleted class="doc doc-heading"> <span class="doc doc-object-name doc-function-name">on_component_class_deleted</span> <a href=#django_components.extension.ComponentExtension.on_component_class_deleted class=headerlink title="Permanent link">¤</a></h3> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=nf>on_component_class_deleted</span><span class=p>(</span><span class=n>ctx</span><span class=p>:</span> <span class=n><a class="autorefs autorefs-internal" title=" OnComponentClassDeletedContext (django_components.extension.OnComponentClassDeletedContext)" href=#django_components.extension.OnComponentClassDeletedContext>OnComponentClassDeletedContext</a></span><span class=p>)</span> <span class=o>-&gt;</span> <span class=kc>None</span>
</code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/extension.py#L560 target=_blank>See source code</a></p> <p>Called when a <a href=../api/#django_components.Component><code>Component</code></a> class is being deleted.</p> <p>This hook is called before the <a href=../api/#django_components.Component><code>Component</code></a> class is deleted from memory.</p> <p>Use this hook to perform any cleanup related to the <a href=../api/#django_components.Component><code>Component</code></a> class.</p> <p><strong>Example:</strong></p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=kn>from</span><span class=w> </span><span class=nn>django_components</span><span class=w> </span><span class=kn>import</span> <span class=n>ComponentExtension</span><span class=p>,</span> <span class=n>OnComponentClassDeletedContext</span> </code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/extension.py#L559 target=_blank>See source code</a></p> <p>Called when a <a href=../api/#django_components.Component><code>Component</code></a> class is being deleted.</p> <p>This hook is called before the <a href=../api/#django_components.Component><code>Component</code></a> class is deleted from memory.</p> <p>Use this hook to perform any cleanup related to the <a href=../api/#django_components.Component><code>Component</code></a> class.</p> <p><strong>Example:</strong></p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=kn>from</span><span class=w> </span><span class=nn>django_components</span><span class=w> </span><span class=kn>import</span> <span class=n>ComponentExtension</span><span class=p>,</span> <span class=n>OnComponentClassDeletedContext</span>
<a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a> <a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a>
<a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a><span class=k>class</span><span class=w> </span><span class=nc>MyExtension</span><span class=p>(</span><span class=n>ComponentExtension</span><span class=p>):</span> <a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a><span class=k>class</span><span class=w> </span><span class=nc>MyExtension</span><span class=p>(</span><span class=n>ComponentExtension</span><span class=p>):</span>
<a id=__codelineno-0-4 name=__codelineno-0-4 href=#__codelineno-0-4></a> <span class=k>def</span><span class=w> </span><span class=nf>on_component_class_deleted</span><span class=p>(</span><span class=bp>self</span><span class=p>,</span> <span class=n>ctx</span><span class=p>:</span> <span class=n>OnComponentClassDeletedContext</span><span class=p>)</span> <span class=o>-&gt;</span> <span class=kc>None</span><span class=p>:</span> <a id=__codelineno-0-4 name=__codelineno-0-4 href=#__codelineno-0-4></a> <span class=k>def</span><span class=w> </span><span class=nf>on_component_class_deleted</span><span class=p>(</span><span class=bp>self</span><span class=p>,</span> <span class=n>ctx</span><span class=p>:</span> <span class=n>OnComponentClassDeletedContext</span><span class=p>)</span> <span class=o>-&gt;</span> <span class=kc>None</span><span class=p>:</span>
<a id=__codelineno-0-5 name=__codelineno-0-5 href=#__codelineno-0-5></a> <span class=c1># Remove Component class from the extension&#39;s cache on deletion</span> <a id=__codelineno-0-5 name=__codelineno-0-5 href=#__codelineno-0-5></a> <span class=c1># Remove Component class from the extension&#39;s cache on deletion</span>
<a id=__codelineno-0-6 name=__codelineno-0-6 href=#__codelineno-0-6></a> <span class=bp>self</span><span class=o>.</span><span class=n>cache</span><span class=o>.</span><span class=n>pop</span><span class=p>(</span><span class=n>ctx</span><span class=o>.</span><span class=n>component_cls</span><span class=p>,</span> <span class=kc>None</span><span class=p>)</span> <a id=__codelineno-0-6 name=__codelineno-0-6 href=#__codelineno-0-6></a> <span class=bp>self</span><span class=o>.</span><span class=n>cache</span><span class=o>.</span><span class=n>pop</span><span class=p>(</span><span class=n>ctx</span><span class=o>.</span><span class=n>component_cls</span><span class=p>,</span> <span class=kc>None</span><span class=p>)</span>
</code></pre></div> </div> </div><p><strong>Available data:</strong></p> <table> <thead> <tr> <th>name</th> <th>type</th> <th>description</th> </tr> </thead> <tbody> <tr> <td><code>component_cls</code></td> <td><a href=../api#django_components.Component><code>Type[Component]</code></a></td> <td>The to-be-deleted Component class</td> </tr> </tbody> </table> <div class="doc doc-object doc-function"> <h3 id=django_components.extension.ComponentExtension.on_component_data class="doc doc-heading"> <span class="doc doc-object-name doc-function-name">on_component_data</span> <a href=#django_components.extension.ComponentExtension.on_component_data class=headerlink title="Permanent link">¤</a></h3> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=nf>on_component_data</span><span class=p>(</span><span class=n>ctx</span><span class=p>:</span> <span class=n><a class="autorefs autorefs-internal" title=" OnComponentDataContext (django_components.extension.OnComponentDataContext)" href=#django_components.extension.OnComponentDataContext>OnComponentDataContext</a></span><span class=p>)</span> <span class=o>-&gt;</span> <span class=kc>None</span> </code></pre></div> </div> </div><p><strong>Available data:</strong></p> <table> <thead> <tr> <th>name</th> <th>type</th> <th>description</th> </tr> </thead> <tbody> <tr> <td><code>component_cls</code></td> <td><a href=../api#django_components.Component><code>Type[Component]</code></a></td> <td>The to-be-deleted Component class</td> </tr> </tbody> </table> <div class="doc doc-object doc-function"> <h3 id=django_components.extension.ComponentExtension.on_component_data class="doc doc-heading"> <span class="doc doc-object-name doc-function-name">on_component_data</span> <a href=#django_components.extension.ComponentExtension.on_component_data class=headerlink title="Permanent link">¤</a></h3> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=nf>on_component_data</span><span class=p>(</span><span class=n>ctx</span><span class=p>:</span> <span class=n><a class="autorefs autorefs-internal" title=" OnComponentDataContext (django_components.extension.OnComponentDataContext)" href=#django_components.extension.OnComponentDataContext>OnComponentDataContext</a></span><span class=p>)</span> <span class=o>-&gt;</span> <span class=kc>None</span>
</code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/extension.py#L717 target=_blank>See source code</a></p> <p>Called when a <a href=../api/#django_components.Component><code>Component</code></a> was triggered to render, after a component's context and data methods have been processed.</p> <p>This hook is called after <a href=../api/#django_components.Component.get_template_data><code>Component.get_template_data()</code></a>, <a href=../api/#django_components.Component.get_js_data><code>Component.get_js_data()</code></a> and <a href=../api/#django_components.Component.get_css_data><code>Component.get_css_data()</code></a>.</p> <p>This hook runs after <a href=../api/#django_components.ComponentExtension.on_component_input><code>on_component_input</code></a>.</p> <p>Use this hook to modify or validate the component's data before rendering.</p> <p><strong>Example:</strong></p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=kn>from</span><span class=w> </span><span class=nn>django_components</span><span class=w> </span><span class=kn>import</span> <span class=n>ComponentExtension</span><span class=p>,</span> <span class=n>OnComponentDataContext</span> </code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/extension.py#L710 target=_blank>See source code</a></p> <p>Called when a <a href=../api/#django_components.Component><code>Component</code></a> was triggered to render, after a component's context and data methods have been processed.</p> <p>This hook is called after <a href=../api/#django_components.Component.get_template_data><code>Component.get_template_data()</code></a>, <a href=../api/#django_components.Component.get_js_data><code>Component.get_js_data()</code></a> and <a href=../api/#django_components.Component.get_css_data><code>Component.get_css_data()</code></a>.</p> <p>This hook runs after <a href=../api/#django_components.ComponentExtension.on_component_input><code>on_component_input</code></a>.</p> <p>Use this hook to modify or validate the component's data before rendering.</p> <p><strong>Example:</strong></p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=kn>from</span><span class=w> </span><span class=nn>django_components</span><span class=w> </span><span class=kn>import</span> <span class=n>ComponentExtension</span><span class=p>,</span> <span class=n>OnComponentDataContext</span>
<a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a> <a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a>
<a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a><span class=k>class</span><span class=w> </span><span class=nc>MyExtension</span><span class=p>(</span><span class=n>ComponentExtension</span><span class=p>):</span> <a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a><span class=k>class</span><span class=w> </span><span class=nc>MyExtension</span><span class=p>(</span><span class=n>ComponentExtension</span><span class=p>):</span>
<a id=__codelineno-0-4 name=__codelineno-0-4 href=#__codelineno-0-4></a> <span class=k>def</span><span class=w> </span><span class=nf>on_component_data</span><span class=p>(</span><span class=bp>self</span><span class=p>,</span> <span class=n>ctx</span><span class=p>:</span> <span class=n>OnComponentDataContext</span><span class=p>)</span> <span class=o>-&gt;</span> <span class=kc>None</span><span class=p>:</span> <a id=__codelineno-0-4 name=__codelineno-0-4 href=#__codelineno-0-4></a> <span class=k>def</span><span class=w> </span><span class=nf>on_component_data</span><span class=p>(</span><span class=bp>self</span><span class=p>,</span> <span class=n>ctx</span><span class=p>:</span> <span class=n>OnComponentDataContext</span><span class=p>)</span> <span class=o>-&gt;</span> <span class=kc>None</span><span class=p>:</span>
<a id=__codelineno-0-5 name=__codelineno-0-5 href=#__codelineno-0-5></a> <span class=c1># Add extra template variable to all components when they are rendered</span> <a id=__codelineno-0-5 name=__codelineno-0-5 href=#__codelineno-0-5></a> <span class=c1># Add extra template variable to all components when they are rendered</span>
<a id=__codelineno-0-6 name=__codelineno-0-6 href=#__codelineno-0-6></a> <span class=n>ctx</span><span class=o>.</span><span class=n>template_data</span><span class=p>[</span><span class=s2>&quot;my_template_var&quot;</span><span class=p>]</span> <span class=o>=</span> <span class=s2>&quot;my_value&quot;</span> <a id=__codelineno-0-6 name=__codelineno-0-6 href=#__codelineno-0-6></a> <span class=n>ctx</span><span class=o>.</span><span class=n>template_data</span><span class=p>[</span><span class=s2>&quot;my_template_var&quot;</span><span class=p>]</span> <span class=o>=</span> <span class=s2>&quot;my_value&quot;</span>
</code></pre></div> </div> </div><p><strong>Available data:</strong></p> <table> <thead> <tr> <th>name</th> <th>type</th> <th>description</th> </tr> </thead> <tbody> <tr> <td><code>component</code></td> <td><a href=../api#django_components.Component><code>Component</code></a></td> <td>The Component instance that is being rendered</td> </tr> <tr> <td><code>component_cls</code></td> <td><a href=../api#django_components.Component><code>Type[Component]</code></a></td> <td>The Component class</td> </tr> <tr> <td><code>component_id</code></td> <td><code>str</code></td> <td>The unique identifier for this component instance</td> </tr> <tr> <td><code>context_data</code></td> <td><code>Dict</code></td> <td>Deprecated. Use <code>template_data</code> instead. Will be removed in v1.0.</td> </tr> <tr> <td><code>css_data</code></td> <td><code>Dict</code></td> <td>Dictionary of CSS data from <code>Component.get_css_data()</code></td> </tr> <tr> <td><code>js_data</code></td> <td><code>Dict</code></td> <td>Dictionary of JavaScript data from <code>Component.get_js_data()</code></td> </tr> <tr> <td><code>template_data</code></td> <td><code>Dict</code></td> <td>Dictionary of template data from <code>Component.get_template_data()</code></td> </tr> </tbody> </table> <div class="doc doc-object doc-function"> <h3 id=django_components.extension.ComponentExtension.on_component_input class="doc doc-heading"> <span class="doc doc-object-name doc-function-name">on_component_input</span> <a href=#django_components.extension.ComponentExtension.on_component_input class=headerlink title="Permanent link">¤</a></h3> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=nf>on_component_input</span><span class=p>(</span><span class=n>ctx</span><span class=p>:</span> <span class=n><a class="autorefs autorefs-internal" title=" OnComponentInputContext (django_components.extension.OnComponentInputContext)" href=#django_components.extension.OnComponentInputContext>OnComponentInputContext</a></span><span class=p>)</span> <span class=o>-&gt;</span> <span class=n><a class="autorefs autorefs-external" title=typing.Optional href=https://docs.python.org/3.12/library/typing.html#typing.Optional>Optional</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/stdtypes.html#str>str</a></span><span class=p>]</span> </code></pre></div> </div> </div><p><strong>Available data:</strong></p> <table> <thead> <tr> <th>name</th> <th>type</th> <th>description</th> </tr> </thead> <tbody> <tr> <td><code>component</code></td> <td><a href=../api#django_components.Component><code>Component</code></a></td> <td>The Component instance that is being rendered</td> </tr> <tr> <td><code>component_cls</code></td> <td><a href=../api#django_components.Component><code>Type[Component]</code></a></td> <td>The Component class</td> </tr> <tr> <td><code>component_id</code></td> <td><code>str</code></td> <td>The unique identifier for this component instance</td> </tr> <tr> <td><code>context_data</code></td> <td><code>Dict</code></td> <td>Deprecated. Use <code>template_data</code> instead. Will be removed in v1.0.</td> </tr> <tr> <td><code>css_data</code></td> <td><code>Dict</code></td> <td>Dictionary of CSS data from <code>Component.get_css_data()</code></td> </tr> <tr> <td><code>js_data</code></td> <td><code>Dict</code></td> <td>Dictionary of JavaScript data from <code>Component.get_js_data()</code></td> </tr> <tr> <td><code>template_data</code></td> <td><code>Dict</code></td> <td>Dictionary of template data from <code>Component.get_template_data()</code></td> </tr> </tbody> </table> <div class="doc doc-object doc-function"> <h3 id=django_components.extension.ComponentExtension.on_component_input class="doc doc-heading"> <span class="doc doc-object-name doc-function-name">on_component_input</span> <a href=#django_components.extension.ComponentExtension.on_component_input class=headerlink title="Permanent link">¤</a></h3> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=nf>on_component_input</span><span class=p>(</span><span class=n>ctx</span><span class=p>:</span> <span class=n><a class="autorefs autorefs-internal" title=" OnComponentInputContext (django_components.extension.OnComponentInputContext)" href=#django_components.extension.OnComponentInputContext>OnComponentInputContext</a></span><span class=p>)</span> <span class=o>-&gt;</span> <span class=n><a class="autorefs autorefs-external" title=typing.Optional href=https://docs.python.org/3.12/library/typing.html#typing.Optional>Optional</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/stdtypes.html#str>str</a></span><span class=p>]</span>
</code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/extension.py#L670 target=_blank>See source code</a></p> <p>Called when a <a href=../api/#django_components.Component><code>Component</code></a> was triggered to render, but before a component's context and data methods are invoked.</p> <p>Use this hook to modify or validate component inputs before they're processed.</p> <p>This is the first hook that is called when rendering a component. As such this hook is called before <a href=../api/#django_components.Component.get_template_data><code>Component.get_template_data()</code></a>, <a href=../api/#django_components.Component.get_js_data><code>Component.get_js_data()</code></a>, and <a href=../api/#django_components.Component.get_css_data><code>Component.get_css_data()</code></a> methods, and the <a href=./#django_components.extension.ComponentExtension.on_component_data><code>on_component_data</code></a> hook.</p> <p>This hook also allows to skip the rendering of a component altogether. If the hook returns a non-null value, this value will be used instead of rendering the component.</p> <p>You can use this to implement a caching mechanism for components, or define components that will be rendered conditionally.</p> <p><strong>Example:</strong></p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=kn>from</span><span class=w> </span><span class=nn>django_components</span><span class=w> </span><span class=kn>import</span> <span class=n>ComponentExtension</span><span class=p>,</span> <span class=n>OnComponentInputContext</span> </code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/extension.py#L664 target=_blank>See source code</a></p> <p>Called when a <a href=../api/#django_components.Component><code>Component</code></a> was triggered to render, but before a component's context and data methods are invoked.</p> <p>Use this hook to modify or validate component inputs before they're processed.</p> <p>This is the first hook that is called when rendering a component. As such this hook is called before <a href=../api/#django_components.Component.get_template_data><code>Component.get_template_data()</code></a>, <a href=../api/#django_components.Component.get_js_data><code>Component.get_js_data()</code></a>, and <a href=../api/#django_components.Component.get_css_data><code>Component.get_css_data()</code></a> methods, and the <a href=./#django_components.extension.ComponentExtension.on_component_data><code>on_component_data</code></a> hook.</p> <p>This hook also allows to skip the rendering of a component altogether. If the hook returns a non-null value, this value will be used instead of rendering the component.</p> <p>You can use this to implement a caching mechanism for components, or define components that will be rendered conditionally.</p> <p><strong>Example:</strong></p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=kn>from</span><span class=w> </span><span class=nn>django_components</span><span class=w> </span><span class=kn>import</span> <span class=n>ComponentExtension</span><span class=p>,</span> <span class=n>OnComponentInputContext</span>
<a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a> <a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a>
<a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a><span class=k>class</span><span class=w> </span><span class=nc>MyExtension</span><span class=p>(</span><span class=n>ComponentExtension</span><span class=p>):</span> <a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a><span class=k>class</span><span class=w> </span><span class=nc>MyExtension</span><span class=p>(</span><span class=n>ComponentExtension</span><span class=p>):</span>
<a id=__codelineno-0-4 name=__codelineno-0-4 href=#__codelineno-0-4></a> <span class=k>def</span><span class=w> </span><span class=nf>on_component_input</span><span class=p>(</span><span class=bp>self</span><span class=p>,</span> <span class=n>ctx</span><span class=p>:</span> <span class=n>OnComponentInputContext</span><span class=p>)</span> <span class=o>-&gt;</span> <span class=kc>None</span><span class=p>:</span> <a id=__codelineno-0-4 name=__codelineno-0-4 href=#__codelineno-0-4></a> <span class=k>def</span><span class=w> </span><span class=nf>on_component_input</span><span class=p>(</span><span class=bp>self</span><span class=p>,</span> <span class=n>ctx</span><span class=p>:</span> <span class=n>OnComponentInputContext</span><span class=p>)</span> <span class=o>-&gt;</span> <span class=kc>None</span><span class=p>:</span>
<a id=__codelineno-0-5 name=__codelineno-0-5 href=#__codelineno-0-5></a> <span class=c1># Add extra kwarg to all components when they are rendered</span> <a id=__codelineno-0-5 name=__codelineno-0-5 href=#__codelineno-0-5></a> <span class=c1># Add extra kwarg to all components when they are rendered</span>
<a id=__codelineno-0-6 name=__codelineno-0-6 href=#__codelineno-0-6></a> <span class=n>ctx</span><span class=o>.</span><span class=n>kwargs</span><span class=p>[</span><span class=s2>&quot;my_input&quot;</span><span class=p>]</span> <span class=o>=</span> <span class=s2>&quot;my_value&quot;</span> <a id=__codelineno-0-6 name=__codelineno-0-6 href=#__codelineno-0-6></a> <span class=n>ctx</span><span class=o>.</span><span class=n>kwargs</span><span class=p>[</span><span class=s2>&quot;my_input&quot;</span><span class=p>]</span> <span class=o>=</span> <span class=s2>&quot;my_value&quot;</span>
</code></pre></div> <div class="admonition warning"> <p class=admonition-title>Warning</p> <p>In this hook, the components' inputs are still mutable.</p> <p>As such, if a component defines <a href=../api/#django_components.Component.Args><code>Args</code></a>, <a href=../api/#django_components.Component.Kwargs><code>Kwargs</code></a>, <a href=../api/#django_components.Component.Slots><code>Slots</code></a> types, these types are NOT yet instantiated.</p> <p>Instead, component fields like <a href=../api/#django_components.Component.args><code>Component.args</code></a>, <a href=../api/#django_components.Component.kwargs><code>Component.kwargs</code></a>, <a href=../api/#django_components.Component.slots><code>Component.slots</code></a> are plain <code>list</code> / <code>dict</code> objects.</p> </div> </div> </div><p><strong>Available data:</strong></p> <table> <thead> <tr> <th>name</th> <th>type</th> <th>description</th> </tr> </thead> <tbody> <tr> <td><code>args</code></td> <td><code>List</code></td> <td>List of positional arguments passed to the component</td> </tr> <tr> <td><code>component</code></td> <td><a href=../api#django_components.Component><code>Component</code></a></td> <td>The Component instance that received the input and is being rendered</td> </tr> <tr> <td><code>component_cls</code></td> <td><a href=../api#django_components.Component><code>Type[Component]</code></a></td> <td>The Component class</td> </tr> <tr> <td><code>component_id</code></td> <td><code>str</code></td> <td>The unique identifier for this component instance</td> </tr> <tr> <td><code>context</code></td> <td><a href=https://docs.djangoproject.com/en/5.2/ref/templates/api/#django.template.Context><code>Context</code></a></td> <td>The Django template Context object</td> </tr> <tr> <td><code>kwargs</code></td> <td><code>Dict</code></td> <td>Dictionary of keyword arguments passed to the component</td> </tr> <tr> <td><code>slots</code></td> <td><code>Dict[str, Slot]</code></td> <td>Dictionary of slot definitions</td> </tr> </tbody> </table> <div class="doc doc-object doc-function"> <h3 id=django_components.extension.ComponentExtension.on_component_registered class="doc doc-heading"> <span class="doc doc-object-name doc-function-name">on_component_registered</span> <a href=#django_components.extension.ComponentExtension.on_component_registered class=headerlink title="Permanent link">¤</a></h3> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=nf>on_component_registered</span><span class=p>(</span><span class=n>ctx</span><span class=p>:</span> <span class=n><a class="autorefs autorefs-internal" title=" OnComponentRegisteredContext (django_components.extension.OnComponentRegisteredContext)" href=#django_components.extension.OnComponentRegisteredContext>OnComponentRegisteredContext</a></span><span class=p>)</span> <span class=o>-&gt;</span> <span class=kc>None</span> </code></pre></div> <div class="admonition warning"> <p class=admonition-title>Warning</p> <p>In this hook, the components' inputs are still mutable.</p> <p>As such, if a component defines <a href=../api/#django_components.Component.Args><code>Args</code></a>, <a href=../api/#django_components.Component.Kwargs><code>Kwargs</code></a>, <a href=../api/#django_components.Component.Slots><code>Slots</code></a> types, these types are NOT yet instantiated.</p> <p>Instead, component fields like <a href=../api/#django_components.Component.args><code>Component.args</code></a>, <a href=../api/#django_components.Component.kwargs><code>Component.kwargs</code></a>, <a href=../api/#django_components.Component.slots><code>Component.slots</code></a> are plain <code>list</code> / <code>dict</code> objects.</p> </div> </div> </div><p><strong>Available data:</strong></p> <table> <thead> <tr> <th>name</th> <th>type</th> <th>description</th> </tr> </thead> <tbody> <tr> <td><code>args</code></td> <td><code>List</code></td> <td>List of positional arguments passed to the component</td> </tr> <tr> <td><code>component</code></td> <td><a href=../api#django_components.Component><code>Component</code></a></td> <td>The Component instance that received the input and is being rendered</td> </tr> <tr> <td><code>component_cls</code></td> <td><a href=../api#django_components.Component><code>Type[Component]</code></a></td> <td>The Component class</td> </tr> <tr> <td><code>component_id</code></td> <td><code>str</code></td> <td>The unique identifier for this component instance</td> </tr> <tr> <td><code>context</code></td> <td><a href=https://docs.djangoproject.com/en/5.2/ref/templates/api/#django.template.Context><code>Context</code></a></td> <td>The Django template Context object</td> </tr> <tr> <td><code>kwargs</code></td> <td><code>Dict</code></td> <td>Dictionary of keyword arguments passed to the component</td> </tr> <tr> <td><code>slots</code></td> <td><code>Dict[str, Slot]</code></td> <td>Dictionary of slot definitions</td> </tr> </tbody> </table> <div class="doc doc-object doc-function"> <h3 id=django_components.extension.ComponentExtension.on_component_registered class="doc doc-heading"> <span class="doc doc-object-name doc-function-name">on_component_registered</span> <a href=#django_components.extension.ComponentExtension.on_component_registered class=headerlink title="Permanent link">¤</a></h3> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=nf>on_component_registered</span><span class=p>(</span><span class=n>ctx</span><span class=p>:</span> <span class=n><a class="autorefs autorefs-internal" title=" OnComponentRegisteredContext (django_components.extension.OnComponentRegisteredContext)" href=#django_components.extension.OnComponentRegisteredContext>OnComponentRegisteredContext</a></span><span class=p>)</span> <span class=o>-&gt;</span> <span class=kc>None</span>
</code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/extension.py#L626 target=_blank>See source code</a></p> <p>Called when a <a href=../api/#django_components.Component><code>Component</code></a> class is registered with a <a href=../api/#django_components.ComponentRegistry><code>ComponentRegistry</code></a>.</p> <p>This hook is called after a <a href=../api/#django_components.Component><code>Component</code></a> class is successfully registered.</p> <p><strong>Example:</strong></p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=kn>from</span><span class=w> </span><span class=nn>django_components</span><span class=w> </span><span class=kn>import</span> <span class=n>ComponentExtension</span><span class=p>,</span> <span class=n>OnComponentRegisteredContext</span> </code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/extension.py#L622 target=_blank>See source code</a></p> <p>Called when a <a href=../api/#django_components.Component><code>Component</code></a> class is registered with a <a href=../api/#django_components.ComponentRegistry><code>ComponentRegistry</code></a>.</p> <p>This hook is called after a <a href=../api/#django_components.Component><code>Component</code></a> class is successfully registered.</p> <p><strong>Example:</strong></p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=kn>from</span><span class=w> </span><span class=nn>django_components</span><span class=w> </span><span class=kn>import</span> <span class=n>ComponentExtension</span><span class=p>,</span> <span class=n>OnComponentRegisteredContext</span>
<a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a> <a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a>
<a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a><span class=k>class</span><span class=w> </span><span class=nc>MyExtension</span><span class=p>(</span><span class=n>ComponentExtension</span><span class=p>):</span> <a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a><span class=k>class</span><span class=w> </span><span class=nc>MyExtension</span><span class=p>(</span><span class=n>ComponentExtension</span><span class=p>):</span>
<a id=__codelineno-0-4 name=__codelineno-0-4 href=#__codelineno-0-4></a> <span class=k>def</span><span class=w> </span><span class=nf>on_component_registered</span><span class=p>(</span><span class=bp>self</span><span class=p>,</span> <span class=n>ctx</span><span class=p>:</span> <span class=n>OnComponentRegisteredContext</span><span class=p>)</span> <span class=o>-&gt;</span> <span class=kc>None</span><span class=p>:</span> <a id=__codelineno-0-4 name=__codelineno-0-4 href=#__codelineno-0-4></a> <span class=k>def</span><span class=w> </span><span class=nf>on_component_registered</span><span class=p>(</span><span class=bp>self</span><span class=p>,</span> <span class=n>ctx</span><span class=p>:</span> <span class=n>OnComponentRegisteredContext</span><span class=p>)</span> <span class=o>-&gt;</span> <span class=kc>None</span><span class=p>:</span>
<a id=__codelineno-0-5 name=__codelineno-0-5 href=#__codelineno-0-5></a> <span class=nb>print</span><span class=p>(</span><span class=sa>f</span><span class=s2>&quot;Component </span><span class=si>{</span><span class=n>ctx</span><span class=o>.</span><span class=n>component_cls</span><span class=si>}</span><span class=s2> registered to </span><span class=si>{</span><span class=n>ctx</span><span class=o>.</span><span class=n>registry</span><span class=si>}</span><span class=s2> as &#39;</span><span class=si>{</span><span class=n>ctx</span><span class=o>.</span><span class=n>name</span><span class=si>}</span><span class=s2>&#39;&quot;</span><span class=p>)</span> <a id=__codelineno-0-5 name=__codelineno-0-5 href=#__codelineno-0-5></a> <span class=nb>print</span><span class=p>(</span><span class=sa>f</span><span class=s2>&quot;Component </span><span class=si>{</span><span class=n>ctx</span><span class=o>.</span><span class=n>component_cls</span><span class=si>}</span><span class=s2> registered to </span><span class=si>{</span><span class=n>ctx</span><span class=o>.</span><span class=n>registry</span><span class=si>}</span><span class=s2> as &#39;</span><span class=si>{</span><span class=n>ctx</span><span class=o>.</span><span class=n>name</span><span class=si>}</span><span class=s2>&#39;&quot;</span><span class=p>)</span>
</code></pre></div> </div> </div><p><strong>Available data:</strong></p> <table> <thead> <tr> <th>name</th> <th>type</th> <th>description</th> </tr> </thead> <tbody> <tr> <td><code>component_cls</code></td> <td><a href=../api#django_components.Component><code>Type[Component]</code></a></td> <td>The registered Component class</td> </tr> <tr> <td><code>name</code></td> <td><code>str</code></td> <td>The name the component was registered under</td> </tr> <tr> <td><code>registry</code></td> <td><a href=../api#django_components.ComponentRegistry><code>ComponentRegistry</code></a></td> <td>The registry the component was registered to</td> </tr> </tbody> </table> <div class="doc doc-object doc-function"> <h3 id=django_components.extension.ComponentExtension.on_component_rendered class="doc doc-heading"> <span class="doc doc-object-name doc-function-name">on_component_rendered</span> <a href=#django_components.extension.ComponentExtension.on_component_rendered class=headerlink title="Permanent link">¤</a></h3> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=nf>on_component_rendered</span><span class=p>(</span><span class=n>ctx</span><span class=p>:</span> <span class=n><span title=django_components.extension.OnComponentRenderedContext>OnComponentRenderedContext</span></span><span class=p>)</span> <span class=o>-&gt;</span> <span class=n><a class="autorefs autorefs-external" title=typing.Optional href=https://docs.python.org/3.12/library/typing.html#typing.Optional>Optional</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/stdtypes.html#str>str</a></span><span class=p>]</span> </code></pre></div> </div> </div><p><strong>Available data:</strong></p> <table> <thead> <tr> <th>name</th> <th>type</th> <th>description</th> </tr> </thead> <tbody> <tr> <td><code>component_cls</code></td> <td><a href=../api#django_components.Component><code>Type[Component]</code></a></td> <td>The registered Component class</td> </tr> <tr> <td><code>name</code></td> <td><code>str</code></td> <td>The name the component was registered under</td> </tr> <tr> <td><code>registry</code></td> <td><a href=../api#django_components.ComponentRegistry><code>ComponentRegistry</code></a></td> <td>The registry the component was registered to</td> </tr> </tbody> </table> <div class="doc doc-object doc-function"> <h3 id=django_components.extension.ComponentExtension.on_component_rendered class="doc doc-heading"> <span class="doc doc-object-name doc-function-name">on_component_rendered</span> <a href=#django_components.extension.ComponentExtension.on_component_rendered class=headerlink title="Permanent link">¤</a></h3> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=nf>on_component_rendered</span><span class=p>(</span><span class=n>ctx</span><span class=p>:</span> <span class=n><span title=django_components.extension.OnComponentRenderedContext>OnComponentRenderedContext</span></span><span class=p>)</span> <span class=o>-&gt;</span> <span class=n><a class="autorefs autorefs-external" title=typing.Optional href=https://docs.python.org/3.12/library/typing.html#typing.Optional>Optional</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/stdtypes.html#str>str</a></span><span class=p>]</span>
</code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/extension.py#L744 target=_blank>See source code</a></p> <p>Called when a <a href=../api/#django_components.Component><code>Component</code></a> was rendered, including all its child components.</p> <p>Use this hook to access or post-process the component's rendered output.</p> <p>This hook works similarly to <a href=../api/#django_components.Component.on_render_after><code>Component.on_render_after()</code></a>:</p> <ol> <li> <p>To modify the output, return a new string from this hook. The original output or error will be ignored.</p> </li> <li> <p>To cause this component to return a new error, raise that error. The original output and error will be ignored.</p> </li> <li> <p>If you neither raise nor return string, the original output or error will be used.</p> </li> </ol> <p><strong>Examples:</strong></p> <p>Change the final output of a component:</p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=kn>from</span><span class=w> </span><span class=nn>django_components</span><span class=w> </span><span class=kn>import</span> <span class=n>ComponentExtension</span><span class=p>,</span> <span class=n>OnComponentRenderedContext</span> </code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/extension.py#L736 target=_blank>See source code</a></p> <p>Called when a <a href=../api/#django_components.Component><code>Component</code></a> was rendered, including all its child components.</p> <p>Use this hook to access or post-process the component's rendered output.</p> <p>This hook works similarly to <a href=../api/#django_components.Component.on_render_after><code>Component.on_render_after()</code></a>:</p> <ol> <li> <p>To modify the output, return a new string from this hook. The original output or error will be ignored.</p> </li> <li> <p>To cause this component to return a new error, raise that error. The original output and error will be ignored.</p> </li> <li> <p>If you neither raise nor return string, the original output or error will be used.</p> </li> </ol> <p><strong>Examples:</strong></p> <p>Change the final output of a component:</p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=kn>from</span><span class=w> </span><span class=nn>django_components</span><span class=w> </span><span class=kn>import</span> <span class=n>ComponentExtension</span><span class=p>,</span> <span class=n>OnComponentRenderedContext</span>
<a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a> <a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a>
<a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a><span class=k>class</span><span class=w> </span><span class=nc>MyExtension</span><span class=p>(</span><span class=n>ComponentExtension</span><span class=p>):</span> <a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a><span class=k>class</span><span class=w> </span><span class=nc>MyExtension</span><span class=p>(</span><span class=n>ComponentExtension</span><span class=p>):</span>
<a id=__codelineno-0-4 name=__codelineno-0-4 href=#__codelineno-0-4></a> <span class=k>def</span><span class=w> </span><span class=nf>on_component_rendered</span><span class=p>(</span><span class=bp>self</span><span class=p>,</span> <span class=n>ctx</span><span class=p>:</span> <span class=n>OnComponentRenderedContext</span><span class=p>)</span> <span class=o>-&gt;</span> <span class=n>Optional</span><span class=p>[</span><span class=nb>str</span><span class=p>]:</span> <a id=__codelineno-0-4 name=__codelineno-0-4 href=#__codelineno-0-4></a> <span class=k>def</span><span class=w> </span><span class=nf>on_component_rendered</span><span class=p>(</span><span class=bp>self</span><span class=p>,</span> <span class=n>ctx</span><span class=p>:</span> <span class=n>OnComponentRenderedContext</span><span class=p>)</span> <span class=o>-&gt;</span> <span class=n>Optional</span><span class=p>[</span><span class=nb>str</span><span class=p>]:</span>
@ -170,41 +170,41 @@
<a id=__codelineno-2-9 name=__codelineno-2-9 href=#__codelineno-2-9></a> <span class=c1># The component rendered successfully</span> <a id=__codelineno-2-9 name=__codelineno-2-9 href=#__codelineno-2-9></a> <span class=c1># The component rendered successfully</span>
<a id=__codelineno-2-10 name=__codelineno-2-10 href=#__codelineno-2-10></a> <span class=nb>print</span><span class=p>(</span><span class=sa>f</span><span class=s2>&quot;Result: </span><span class=si>{</span><span class=n>ctx</span><span class=o>.</span><span class=n>result</span><span class=si>}</span><span class=s2>&quot;</span><span class=p>)</span> <a id=__codelineno-2-10 name=__codelineno-2-10 href=#__codelineno-2-10></a> <span class=nb>print</span><span class=p>(</span><span class=sa>f</span><span class=s2>&quot;Result: </span><span class=si>{</span><span class=n>ctx</span><span class=o>.</span><span class=n>result</span><span class=si>}</span><span class=s2>&quot;</span><span class=p>)</span>
</code></pre></div> </div> </div><p><strong>Available data:</strong></p> <table> <thead> <tr> <th>name</th> <th>type</th> <th>description</th> </tr> </thead> <tbody> <tr> <td><code>component</code></td> <td><a href=../api#django_components.Component><code>Component</code></a></td> <td>The Component instance that is being rendered</td> </tr> <tr> <td><code>component_cls</code></td> <td><a href=../api#django_components.Component><code>Type[Component]</code></a></td> <td>The Component class</td> </tr> <tr> <td><code>component_id</code></td> <td><code>str</code></td> <td>The unique identifier for this component instance</td> </tr> <tr> <td><code>error</code></td> <td><code>Optional[Exception]</code></td> <td>The error that occurred during rendering, or <code>None</code> if rendering was successful</td> </tr> <tr> <td><code>result</code></td> <td><code>Optional[str]</code></td> <td>The rendered component, or <code>None</code> if rendering failed</td> </tr> </tbody> </table> <div class="doc doc-object doc-function"> <h3 id=django_components.extension.ComponentExtension.on_component_unregistered class="doc doc-heading"> <span class="doc doc-object-name doc-function-name">on_component_unregistered</span> <a href=#django_components.extension.ComponentExtension.on_component_unregistered class=headerlink title="Permanent link">¤</a></h3> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=nf>on_component_unregistered</span><span class=p>(</span><span class=n>ctx</span><span class=p>:</span> <span class=n><a class="autorefs autorefs-internal" title=" OnComponentUnregisteredContext (django_components.extension.OnComponentUnregisteredContext)" href=#django_components.extension.OnComponentUnregisteredContext>OnComponentUnregisteredContext</a></span><span class=p>)</span> <span class=o>-&gt;</span> <span class=kc>None</span> </code></pre></div> </div> </div><p><strong>Available data:</strong></p> <table> <thead> <tr> <th>name</th> <th>type</th> <th>description</th> </tr> </thead> <tbody> <tr> <td><code>component</code></td> <td><a href=../api#django_components.Component><code>Component</code></a></td> <td>The Component instance that is being rendered</td> </tr> <tr> <td><code>component_cls</code></td> <td><a href=../api#django_components.Component><code>Type[Component]</code></a></td> <td>The Component class</td> </tr> <tr> <td><code>component_id</code></td> <td><code>str</code></td> <td>The unique identifier for this component instance</td> </tr> <tr> <td><code>error</code></td> <td><code>Optional[Exception]</code></td> <td>The error that occurred during rendering, or <code>None</code> if rendering was successful</td> </tr> <tr> <td><code>result</code></td> <td><code>Optional[str]</code></td> <td>The rendered component, or <code>None</code> if rendering failed</td> </tr> </tbody> </table> <div class="doc doc-object doc-function"> <h3 id=django_components.extension.ComponentExtension.on_component_unregistered class="doc doc-heading"> <span class="doc doc-object-name doc-function-name">on_component_unregistered</span> <a href=#django_components.extension.ComponentExtension.on_component_unregistered class=headerlink title="Permanent link">¤</a></h3> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=nf>on_component_unregistered</span><span class=p>(</span><span class=n>ctx</span><span class=p>:</span> <span class=n><a class="autorefs autorefs-internal" title=" OnComponentUnregisteredContext (django_components.extension.OnComponentUnregisteredContext)" href=#django_components.extension.OnComponentUnregisteredContext>OnComponentUnregisteredContext</a></span><span class=p>)</span> <span class=o>-&gt;</span> <span class=kc>None</span>
</code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/extension.py#L646 target=_blank>See source code</a></p> <p>Called when a <a href=../api/#django_components.Component><code>Component</code></a> class is unregistered from a <a href=../api/#django_components.ComponentRegistry><code>ComponentRegistry</code></a>.</p> <p>This hook is called after a <a href=../api/#django_components.Component><code>Component</code></a> class is removed from the registry.</p> <p><strong>Example:</strong></p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=kn>from</span><span class=w> </span><span class=nn>django_components</span><span class=w> </span><span class=kn>import</span> <span class=n>ComponentExtension</span><span class=p>,</span> <span class=n>OnComponentUnregisteredContext</span> </code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/extension.py#L641 target=_blank>See source code</a></p> <p>Called when a <a href=../api/#django_components.Component><code>Component</code></a> class is unregistered from a <a href=../api/#django_components.ComponentRegistry><code>ComponentRegistry</code></a>.</p> <p>This hook is called after a <a href=../api/#django_components.Component><code>Component</code></a> class is removed from the registry.</p> <p><strong>Example:</strong></p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=kn>from</span><span class=w> </span><span class=nn>django_components</span><span class=w> </span><span class=kn>import</span> <span class=n>ComponentExtension</span><span class=p>,</span> <span class=n>OnComponentUnregisteredContext</span>
<a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a> <a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a>
<a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a><span class=k>class</span><span class=w> </span><span class=nc>MyExtension</span><span class=p>(</span><span class=n>ComponentExtension</span><span class=p>):</span> <a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a><span class=k>class</span><span class=w> </span><span class=nc>MyExtension</span><span class=p>(</span><span class=n>ComponentExtension</span><span class=p>):</span>
<a id=__codelineno-0-4 name=__codelineno-0-4 href=#__codelineno-0-4></a> <span class=k>def</span><span class=w> </span><span class=nf>on_component_unregistered</span><span class=p>(</span><span class=bp>self</span><span class=p>,</span> <span class=n>ctx</span><span class=p>:</span> <span class=n>OnComponentUnregisteredContext</span><span class=p>)</span> <span class=o>-&gt;</span> <span class=kc>None</span><span class=p>:</span> <a id=__codelineno-0-4 name=__codelineno-0-4 href=#__codelineno-0-4></a> <span class=k>def</span><span class=w> </span><span class=nf>on_component_unregistered</span><span class=p>(</span><span class=bp>self</span><span class=p>,</span> <span class=n>ctx</span><span class=p>:</span> <span class=n>OnComponentUnregisteredContext</span><span class=p>)</span> <span class=o>-&gt;</span> <span class=kc>None</span><span class=p>:</span>
<a id=__codelineno-0-5 name=__codelineno-0-5 href=#__codelineno-0-5></a> <span class=nb>print</span><span class=p>(</span><span class=sa>f</span><span class=s2>&quot;Component </span><span class=si>{</span><span class=n>ctx</span><span class=o>.</span><span class=n>component_cls</span><span class=si>}</span><span class=s2> unregistered from </span><span class=si>{</span><span class=n>ctx</span><span class=o>.</span><span class=n>registry</span><span class=si>}</span><span class=s2> as &#39;</span><span class=si>{</span><span class=n>ctx</span><span class=o>.</span><span class=n>name</span><span class=si>}</span><span class=s2>&#39;&quot;</span><span class=p>)</span> <a id=__codelineno-0-5 name=__codelineno-0-5 href=#__codelineno-0-5></a> <span class=nb>print</span><span class=p>(</span><span class=sa>f</span><span class=s2>&quot;Component </span><span class=si>{</span><span class=n>ctx</span><span class=o>.</span><span class=n>component_cls</span><span class=si>}</span><span class=s2> unregistered from </span><span class=si>{</span><span class=n>ctx</span><span class=o>.</span><span class=n>registry</span><span class=si>}</span><span class=s2> as &#39;</span><span class=si>{</span><span class=n>ctx</span><span class=o>.</span><span class=n>name</span><span class=si>}</span><span class=s2>&#39;&quot;</span><span class=p>)</span>
</code></pre></div> </div> </div><p><strong>Available data:</strong></p> <table> <thead> <tr> <th>name</th> <th>type</th> <th>description</th> </tr> </thead> <tbody> <tr> <td><code>component_cls</code></td> <td><a href=../api#django_components.Component><code>Type[Component]</code></a></td> <td>The unregistered Component class</td> </tr> <tr> <td><code>name</code></td> <td><code>str</code></td> <td>The name the component was registered under</td> </tr> <tr> <td><code>registry</code></td> <td><a href=../api#django_components.ComponentRegistry><code>ComponentRegistry</code></a></td> <td>The registry the component was unregistered from</td> </tr> </tbody> </table> <div class="doc doc-object doc-function"> <h3 id=django_components.extension.ComponentExtension.on_css_loaded class="doc doc-heading"> <span class="doc doc-object-name doc-function-name">on_css_loaded</span> <a href=#django_components.extension.ComponentExtension.on_css_loaded class=headerlink title="Permanent link">¤</a></h3> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=nf>on_css_loaded</span><span class=p>(</span><span class=n>ctx</span><span class=p>:</span> <span class=n><span title=django_components.extension.OnCssLoadedContext>OnCssLoadedContext</span></span><span class=p>)</span> <span class=o>-&gt;</span> <span class=n><a class="autorefs autorefs-external" title=typing.Optional href=https://docs.python.org/3.12/library/typing.html#typing.Optional>Optional</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/stdtypes.html#str>str</a></span><span class=p>]</span> </code></pre></div> </div> </div><p><strong>Available data:</strong></p> <table> <thead> <tr> <th>name</th> <th>type</th> <th>description</th> </tr> </thead> <tbody> <tr> <td><code>component_cls</code></td> <td><a href=../api#django_components.Component><code>Type[Component]</code></a></td> <td>The unregistered Component class</td> </tr> <tr> <td><code>name</code></td> <td><code>str</code></td> <td>The name the component was registered under</td> </tr> <tr> <td><code>registry</code></td> <td><a href=../api#django_components.ComponentRegistry><code>ComponentRegistry</code></a></td> <td>The registry the component was unregistered from</td> </tr> </tbody> </table> <div class="doc doc-object doc-function"> <h3 id=django_components.extension.ComponentExtension.on_css_loaded class="doc doc-heading"> <span class="doc doc-object-name doc-function-name">on_css_loaded</span> <a href=#django_components.extension.ComponentExtension.on_css_loaded class=headerlink title="Permanent link">¤</a></h3> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=nf>on_css_loaded</span><span class=p>(</span><span class=n>ctx</span><span class=p>:</span> <span class=n><span title=django_components.extension.OnCssLoadedContext>OnCssLoadedContext</span></span><span class=p>)</span> <span class=o>-&gt;</span> <span class=n><a class="autorefs autorefs-external" title=typing.Optional href=https://docs.python.org/3.12/library/typing.html#typing.Optional>Optional</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/stdtypes.html#str>str</a></span><span class=p>]</span>
</code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/extension.py#L854 target=_blank>See source code</a></p> <p>Called when a Component's CSS is loaded as a string.</p> <p>This hook runs only once per <a href=../api/#django_components.Component><code>Component</code></a> class and works for both <a href=../api/#django_components.Component.css><code>Component.css</code></a> and <a href=../api/#django_components.Component.css_file><code>Component.css_file</code></a>.</p> <p>Use this hook to read or modify the CSS.</p> <p>To modify the CSS, return a new string from this hook.</p> <p><strong>Example:</strong></p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=kn>from</span><span class=w> </span><span class=nn>django_components</span><span class=w> </span><span class=kn>import</span> <span class=n>ComponentExtension</span><span class=p>,</span> <span class=n>OnCssLoadedContext</span> </code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/extension.py#L843 target=_blank>See source code</a></p> <p>Called when a Component's CSS is loaded as a string.</p> <p>This hook runs only once per <a href=../api/#django_components.Component><code>Component</code></a> class and works for both <a href=../api/#django_components.Component.css><code>Component.css</code></a> and <a href=../api/#django_components.Component.css_file><code>Component.css_file</code></a>.</p> <p>Use this hook to read or modify the CSS.</p> <p>To modify the CSS, return a new string from this hook.</p> <p><strong>Example:</strong></p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=kn>from</span><span class=w> </span><span class=nn>django_components</span><span class=w> </span><span class=kn>import</span> <span class=n>ComponentExtension</span><span class=p>,</span> <span class=n>OnCssLoadedContext</span>
<a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a> <a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a>
<a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a><span class=k>class</span><span class=w> </span><span class=nc>MyExtension</span><span class=p>(</span><span class=n>ComponentExtension</span><span class=p>):</span> <a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a><span class=k>class</span><span class=w> </span><span class=nc>MyExtension</span><span class=p>(</span><span class=n>ComponentExtension</span><span class=p>):</span>
<a id=__codelineno-0-4 name=__codelineno-0-4 href=#__codelineno-0-4></a> <span class=k>def</span><span class=w> </span><span class=nf>on_css_loaded</span><span class=p>(</span><span class=bp>self</span><span class=p>,</span> <span class=n>ctx</span><span class=p>:</span> <span class=n>OnCssLoadedContext</span><span class=p>)</span> <span class=o>-&gt;</span> <span class=n>Optional</span><span class=p>[</span><span class=nb>str</span><span class=p>]:</span> <a id=__codelineno-0-4 name=__codelineno-0-4 href=#__codelineno-0-4></a> <span class=k>def</span><span class=w> </span><span class=nf>on_css_loaded</span><span class=p>(</span><span class=bp>self</span><span class=p>,</span> <span class=n>ctx</span><span class=p>:</span> <span class=n>OnCssLoadedContext</span><span class=p>)</span> <span class=o>-&gt;</span> <span class=n>Optional</span><span class=p>[</span><span class=nb>str</span><span class=p>]:</span>
<a id=__codelineno-0-5 name=__codelineno-0-5 href=#__codelineno-0-5></a> <span class=c1># Modify the CSS</span> <a id=__codelineno-0-5 name=__codelineno-0-5 href=#__codelineno-0-5></a> <span class=c1># Modify the CSS</span>
<a id=__codelineno-0-6 name=__codelineno-0-6 href=#__codelineno-0-6></a> <span class=k>return</span> <span class=n>ctx</span><span class=o>.</span><span class=n>content</span><span class=o>.</span><span class=n>replace</span><span class=p>(</span><span class=s2>&quot;Hello&quot;</span><span class=p>,</span> <span class=s2>&quot;Hi&quot;</span><span class=p>)</span> <a id=__codelineno-0-6 name=__codelineno-0-6 href=#__codelineno-0-6></a> <span class=k>return</span> <span class=n>ctx</span><span class=o>.</span><span class=n>content</span><span class=o>.</span><span class=n>replace</span><span class=p>(</span><span class=s2>&quot;Hello&quot;</span><span class=p>,</span> <span class=s2>&quot;Hi&quot;</span><span class=p>)</span>
</code></pre></div> </div> </div><p><strong>Available data:</strong></p> <table> <thead> <tr> <th>name</th> <th>type</th> <th>description</th> </tr> </thead> <tbody> <tr> <td><code>component_cls</code></td> <td><a href=../api#django_components.Component><code>Type[Component]</code></a></td> <td>The Component class whose CSS was loaded</td> </tr> <tr> <td><code>content</code></td> <td><code>str</code></td> <td>The CSS content (string)</td> </tr> </tbody> </table> <div class="doc doc-object doc-function"> <h3 id=django_components.extension.ComponentExtension.on_js_loaded class="doc doc-heading"> <span class="doc doc-object-name doc-function-name">on_js_loaded</span> <a href=#django_components.extension.ComponentExtension.on_js_loaded class=headerlink title="Permanent link">¤</a></h3> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=nf>on_js_loaded</span><span class=p>(</span><span class=n>ctx</span><span class=p>:</span> <span class=n><span title=django_components.extension.OnJsLoadedContext>OnJsLoadedContext</span></span><span class=p>)</span> <span class=o>-&gt;</span> <span class=n><a class="autorefs autorefs-external" title=typing.Optional href=https://docs.python.org/3.12/library/typing.html#typing.Optional>Optional</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/stdtypes.html#str>str</a></span><span class=p>]</span> </code></pre></div> </div> </div><p><strong>Available data:</strong></p> <table> <thead> <tr> <th>name</th> <th>type</th> <th>description</th> </tr> </thead> <tbody> <tr> <td><code>component_cls</code></td> <td><a href=../api#django_components.Component><code>Type[Component]</code></a></td> <td>The Component class whose CSS was loaded</td> </tr> <tr> <td><code>content</code></td> <td><code>str</code></td> <td>The CSS content (string)</td> </tr> </tbody> </table> <div class="doc doc-object doc-function"> <h3 id=django_components.extension.ComponentExtension.on_js_loaded class="doc doc-heading"> <span class="doc doc-object-name doc-function-name">on_js_loaded</span> <a href=#django_components.extension.ComponentExtension.on_js_loaded class=headerlink title="Permanent link">¤</a></h3> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=nf>on_js_loaded</span><span class=p>(</span><span class=n>ctx</span><span class=p>:</span> <span class=n><span title=django_components.extension.OnJsLoadedContext>OnJsLoadedContext</span></span><span class=p>)</span> <span class=o>-&gt;</span> <span class=n><a class="autorefs autorefs-external" title=typing.Optional href=https://docs.python.org/3.12/library/typing.html#typing.Optional>Optional</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/stdtypes.html#str>str</a></span><span class=p>]</span>
</code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/extension.py#L879 target=_blank>See source code</a></p> <p>Called when a Component's JS is loaded as a string.</p> <p>This hook runs only once per <a href=../api/#django_components.Component><code>Component</code></a> class and works for both <a href=../api/#django_components.Component.js><code>Component.js</code></a> and <a href=../api/#django_components.Component.js_file><code>Component.js_file</code></a>.</p> <p>Use this hook to read or modify the JS.</p> <p>To modify the JS, return a new string from this hook.</p> <p><strong>Example:</strong></p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=kn>from</span><span class=w> </span><span class=nn>django_components</span><span class=w> </span><span class=kn>import</span> <span class=n>ComponentExtension</span><span class=p>,</span> <span class=n>OnCssLoadedContext</span> </code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/extension.py#L867 target=_blank>See source code</a></p> <p>Called when a Component's JS is loaded as a string.</p> <p>This hook runs only once per <a href=../api/#django_components.Component><code>Component</code></a> class and works for both <a href=../api/#django_components.Component.js><code>Component.js</code></a> and <a href=../api/#django_components.Component.js_file><code>Component.js_file</code></a>.</p> <p>Use this hook to read or modify the JS.</p> <p>To modify the JS, return a new string from this hook.</p> <p><strong>Example:</strong></p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=kn>from</span><span class=w> </span><span class=nn>django_components</span><span class=w> </span><span class=kn>import</span> <span class=n>ComponentExtension</span><span class=p>,</span> <span class=n>OnCssLoadedContext</span>
<a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a> <a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a>
<a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a><span class=k>class</span><span class=w> </span><span class=nc>MyExtension</span><span class=p>(</span><span class=n>ComponentExtension</span><span class=p>):</span> <a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a><span class=k>class</span><span class=w> </span><span class=nc>MyExtension</span><span class=p>(</span><span class=n>ComponentExtension</span><span class=p>):</span>
<a id=__codelineno-0-4 name=__codelineno-0-4 href=#__codelineno-0-4></a> <span class=k>def</span><span class=w> </span><span class=nf>on_js_loaded</span><span class=p>(</span><span class=bp>self</span><span class=p>,</span> <span class=n>ctx</span><span class=p>:</span> <span class=n>OnJsLoadedContext</span><span class=p>)</span> <span class=o>-&gt;</span> <span class=n>Optional</span><span class=p>[</span><span class=nb>str</span><span class=p>]:</span> <a id=__codelineno-0-4 name=__codelineno-0-4 href=#__codelineno-0-4></a> <span class=k>def</span><span class=w> </span><span class=nf>on_js_loaded</span><span class=p>(</span><span class=bp>self</span><span class=p>,</span> <span class=n>ctx</span><span class=p>:</span> <span class=n>OnJsLoadedContext</span><span class=p>)</span> <span class=o>-&gt;</span> <span class=n>Optional</span><span class=p>[</span><span class=nb>str</span><span class=p>]:</span>
<a id=__codelineno-0-5 name=__codelineno-0-5 href=#__codelineno-0-5></a> <span class=c1># Modify the JS</span> <a id=__codelineno-0-5 name=__codelineno-0-5 href=#__codelineno-0-5></a> <span class=c1># Modify the JS</span>
<a id=__codelineno-0-6 name=__codelineno-0-6 href=#__codelineno-0-6></a> <span class=k>return</span> <span class=n>ctx</span><span class=o>.</span><span class=n>content</span><span class=o>.</span><span class=n>replace</span><span class=p>(</span><span class=s2>&quot;Hello&quot;</span><span class=p>,</span> <span class=s2>&quot;Hi&quot;</span><span class=p>)</span> <a id=__codelineno-0-6 name=__codelineno-0-6 href=#__codelineno-0-6></a> <span class=k>return</span> <span class=n>ctx</span><span class=o>.</span><span class=n>content</span><span class=o>.</span><span class=n>replace</span><span class=p>(</span><span class=s2>&quot;Hello&quot;</span><span class=p>,</span> <span class=s2>&quot;Hi&quot;</span><span class=p>)</span>
</code></pre></div> </div> </div><p><strong>Available data:</strong></p> <table> <thead> <tr> <th>name</th> <th>type</th> <th>description</th> </tr> </thead> <tbody> <tr> <td><code>component_cls</code></td> <td><a href=../api#django_components.Component><code>Type[Component]</code></a></td> <td>The Component class whose JS was loaded</td> </tr> <tr> <td><code>content</code></td> <td><code>str</code></td> <td>The JS content (string)</td> </tr> </tbody> </table> <div class="doc doc-object doc-function"> <h3 id=django_components.extension.ComponentExtension.on_registry_created class="doc doc-heading"> <span class="doc doc-object-name doc-function-name">on_registry_created</span> <a href=#django_components.extension.ComponentExtension.on_registry_created class=headerlink title="Permanent link">¤</a></h3> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=nf>on_registry_created</span><span class=p>(</span><span class=n>ctx</span><span class=p>:</span> <span class=n><a class="autorefs autorefs-internal" title=" OnRegistryCreatedContext (django_components.extension.OnRegistryCreatedContext)" href=#django_components.extension.OnRegistryCreatedContext>OnRegistryCreatedContext</a></span><span class=p>)</span> <span class=o>-&gt;</span> <span class=kc>None</span> </code></pre></div> </div> </div><p><strong>Available data:</strong></p> <table> <thead> <tr> <th>name</th> <th>type</th> <th>description</th> </tr> </thead> <tbody> <tr> <td><code>component_cls</code></td> <td><a href=../api#django_components.Component><code>Type[Component]</code></a></td> <td>The Component class whose JS was loaded</td> </tr> <tr> <td><code>content</code></td> <td><code>str</code></td> <td>The JS content (string)</td> </tr> </tbody> </table> <div class="doc doc-object doc-function"> <h3 id=django_components.extension.ComponentExtension.on_registry_created class="doc doc-heading"> <span class="doc doc-object-name doc-function-name">on_registry_created</span> <a href=#django_components.extension.ComponentExtension.on_registry_created class=headerlink title="Permanent link">¤</a></h3> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=nf>on_registry_created</span><span class=p>(</span><span class=n>ctx</span><span class=p>:</span> <span class=n><a class="autorefs autorefs-internal" title=" OnRegistryCreatedContext (django_components.extension.OnRegistryCreatedContext)" href=#django_components.extension.OnRegistryCreatedContext>OnRegistryCreatedContext</a></span><span class=p>)</span> <span class=o>-&gt;</span> <span class=kc>None</span>
</code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/extension.py#L582 target=_blank>See source code</a></p> <p>Called when a new <a href=../api/#django_components.ComponentRegistry><code>ComponentRegistry</code></a> is created.</p> <p>This hook is called after a new <a href=../api/#django_components.ComponentRegistry><code>ComponentRegistry</code></a> instance is initialized.</p> <p>Use this hook to perform any initialization needed for the registry.</p> <p><strong>Example:</strong></p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=kn>from</span><span class=w> </span><span class=nn>django_components</span><span class=w> </span><span class=kn>import</span> <span class=n>ComponentExtension</span><span class=p>,</span> <span class=n>OnRegistryCreatedContext</span> </code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/extension.py#L580 target=_blank>See source code</a></p> <p>Called when a new <a href=../api/#django_components.ComponentRegistry><code>ComponentRegistry</code></a> is created.</p> <p>This hook is called after a new <a href=../api/#django_components.ComponentRegistry><code>ComponentRegistry</code></a> instance is initialized.</p> <p>Use this hook to perform any initialization needed for the registry.</p> <p><strong>Example:</strong></p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=kn>from</span><span class=w> </span><span class=nn>django_components</span><span class=w> </span><span class=kn>import</span> <span class=n>ComponentExtension</span><span class=p>,</span> <span class=n>OnRegistryCreatedContext</span>
<a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a> <a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a>
<a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a><span class=k>class</span><span class=w> </span><span class=nc>MyExtension</span><span class=p>(</span><span class=n>ComponentExtension</span><span class=p>):</span> <a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a><span class=k>class</span><span class=w> </span><span class=nc>MyExtension</span><span class=p>(</span><span class=n>ComponentExtension</span><span class=p>):</span>
<a id=__codelineno-0-4 name=__codelineno-0-4 href=#__codelineno-0-4></a> <span class=k>def</span><span class=w> </span><span class=nf>on_registry_created</span><span class=p>(</span><span class=bp>self</span><span class=p>,</span> <span class=n>ctx</span><span class=p>:</span> <span class=n>OnRegistryCreatedContext</span><span class=p>)</span> <span class=o>-&gt;</span> <span class=kc>None</span><span class=p>:</span> <a id=__codelineno-0-4 name=__codelineno-0-4 href=#__codelineno-0-4></a> <span class=k>def</span><span class=w> </span><span class=nf>on_registry_created</span><span class=p>(</span><span class=bp>self</span><span class=p>,</span> <span class=n>ctx</span><span class=p>:</span> <span class=n>OnRegistryCreatedContext</span><span class=p>)</span> <span class=o>-&gt;</span> <span class=kc>None</span><span class=p>:</span>
<a id=__codelineno-0-5 name=__codelineno-0-5 href=#__codelineno-0-5></a> <span class=c1># Add a new attribute to the registry</span> <a id=__codelineno-0-5 name=__codelineno-0-5 href=#__codelineno-0-5></a> <span class=c1># Add a new attribute to the registry</span>
<a id=__codelineno-0-6 name=__codelineno-0-6 href=#__codelineno-0-6></a> <span class=n>ctx</span><span class=o>.</span><span class=n>registry</span><span class=o>.</span><span class=n>my_attr</span> <span class=o>=</span> <span class=s2>&quot;my_value&quot;</span> <a id=__codelineno-0-6 name=__codelineno-0-6 href=#__codelineno-0-6></a> <span class=n>ctx</span><span class=o>.</span><span class=n>registry</span><span class=o>.</span><span class=n>my_attr</span> <span class=o>=</span> <span class=s2>&quot;my_value&quot;</span>
</code></pre></div> </div> </div><p><strong>Available data:</strong></p> <table> <thead> <tr> <th>name</th> <th>type</th> <th>description</th> </tr> </thead> <tbody> <tr> <td><code>registry</code></td> <td><a href=../api#django_components.ComponentRegistry><code>ComponentRegistry</code></a></td> <td>The created ComponentRegistry instance</td> </tr> </tbody> </table> <div class="doc doc-object doc-function"> <h3 id=django_components.extension.ComponentExtension.on_registry_deleted class="doc doc-heading"> <span class="doc doc-object-name doc-function-name">on_registry_deleted</span> <a href=#django_components.extension.ComponentExtension.on_registry_deleted class=headerlink title="Permanent link">¤</a></h3> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=nf>on_registry_deleted</span><span class=p>(</span><span class=n>ctx</span><span class=p>:</span> <span class=n><a class="autorefs autorefs-internal" title=" OnRegistryDeletedContext (django_components.extension.OnRegistryDeletedContext)" href=#django_components.extension.OnRegistryDeletedContext>OnRegistryDeletedContext</a></span><span class=p>)</span> <span class=o>-&gt;</span> <span class=kc>None</span> </code></pre></div> </div> </div><p><strong>Available data:</strong></p> <table> <thead> <tr> <th>name</th> <th>type</th> <th>description</th> </tr> </thead> <tbody> <tr> <td><code>registry</code></td> <td><a href=../api#django_components.ComponentRegistry><code>ComponentRegistry</code></a></td> <td>The created ComponentRegistry instance</td> </tr> </tbody> </table> <div class="doc doc-object doc-function"> <h3 id=django_components.extension.ComponentExtension.on_registry_deleted class="doc doc-heading"> <span class="doc doc-object-name doc-function-name">on_registry_deleted</span> <a href=#django_components.extension.ComponentExtension.on_registry_deleted class=headerlink title="Permanent link">¤</a></h3> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=nf>on_registry_deleted</span><span class=p>(</span><span class=n>ctx</span><span class=p>:</span> <span class=n><a class="autorefs autorefs-internal" title=" OnRegistryDeletedContext (django_components.extension.OnRegistryDeletedContext)" href=#django_components.extension.OnRegistryDeletedContext>OnRegistryDeletedContext</a></span><span class=p>)</span> <span class=o>-&gt;</span> <span class=kc>None</span>
</code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/extension.py#L604 target=_blank>See source code</a></p> <p>Called when a <a href=../api/#django_components.ComponentRegistry><code>ComponentRegistry</code></a> is being deleted.</p> <p>This hook is called before a <a href=../api/#django_components.ComponentRegistry><code>ComponentRegistry</code></a> instance is deleted.</p> <p>Use this hook to perform any cleanup related to the registry.</p> <p><strong>Example:</strong></p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=kn>from</span><span class=w> </span><span class=nn>django_components</span><span class=w> </span><span class=kn>import</span> <span class=n>ComponentExtension</span><span class=p>,</span> <span class=n>OnRegistryDeletedContext</span> </code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/extension.py#L601 target=_blank>See source code</a></p> <p>Called when a <a href=../api/#django_components.ComponentRegistry><code>ComponentRegistry</code></a> is being deleted.</p> <p>This hook is called before a <a href=../api/#django_components.ComponentRegistry><code>ComponentRegistry</code></a> instance is deleted.</p> <p>Use this hook to perform any cleanup related to the registry.</p> <p><strong>Example:</strong></p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=kn>from</span><span class=w> </span><span class=nn>django_components</span><span class=w> </span><span class=kn>import</span> <span class=n>ComponentExtension</span><span class=p>,</span> <span class=n>OnRegistryDeletedContext</span>
<a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a> <a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a>
<a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a><span class=k>class</span><span class=w> </span><span class=nc>MyExtension</span><span class=p>(</span><span class=n>ComponentExtension</span><span class=p>):</span> <a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a><span class=k>class</span><span class=w> </span><span class=nc>MyExtension</span><span class=p>(</span><span class=n>ComponentExtension</span><span class=p>):</span>
<a id=__codelineno-0-4 name=__codelineno-0-4 href=#__codelineno-0-4></a> <span class=k>def</span><span class=w> </span><span class=nf>on_registry_deleted</span><span class=p>(</span><span class=bp>self</span><span class=p>,</span> <span class=n>ctx</span><span class=p>:</span> <span class=n>OnRegistryDeletedContext</span><span class=p>)</span> <span class=o>-&gt;</span> <span class=kc>None</span><span class=p>:</span> <a id=__codelineno-0-4 name=__codelineno-0-4 href=#__codelineno-0-4></a> <span class=k>def</span><span class=w> </span><span class=nf>on_registry_deleted</span><span class=p>(</span><span class=bp>self</span><span class=p>,</span> <span class=n>ctx</span><span class=p>:</span> <span class=n>OnRegistryDeletedContext</span><span class=p>)</span> <span class=o>-&gt;</span> <span class=kc>None</span><span class=p>:</span>
<a id=__codelineno-0-5 name=__codelineno-0-5 href=#__codelineno-0-5></a> <span class=c1># Remove registry from the extension&#39;s cache on deletion</span> <a id=__codelineno-0-5 name=__codelineno-0-5 href=#__codelineno-0-5></a> <span class=c1># Remove registry from the extension&#39;s cache on deletion</span>
<a id=__codelineno-0-6 name=__codelineno-0-6 href=#__codelineno-0-6></a> <span class=bp>self</span><span class=o>.</span><span class=n>cache</span><span class=o>.</span><span class=n>pop</span><span class=p>(</span><span class=n>ctx</span><span class=o>.</span><span class=n>registry</span><span class=p>,</span> <span class=kc>None</span><span class=p>)</span> <a id=__codelineno-0-6 name=__codelineno-0-6 href=#__codelineno-0-6></a> <span class=bp>self</span><span class=o>.</span><span class=n>cache</span><span class=o>.</span><span class=n>pop</span><span class=p>(</span><span class=n>ctx</span><span class=o>.</span><span class=n>registry</span><span class=p>,</span> <span class=kc>None</span><span class=p>)</span>
</code></pre></div> </div> </div><p><strong>Available data:</strong></p> <table> <thead> <tr> <th>name</th> <th>type</th> <th>description</th> </tr> </thead> <tbody> <tr> <td><code>registry</code></td> <td><a href=../api#django_components.ComponentRegistry><code>ComponentRegistry</code></a></td> <td>The to-be-deleted ComponentRegistry instance</td> </tr> </tbody> </table> <div class="doc doc-object doc-function"> <h3 id=django_components.extension.ComponentExtension.on_slot_rendered class="doc doc-heading"> <span class="doc doc-object-name doc-function-name">on_slot_rendered</span> <a href=#django_components.extension.ComponentExtension.on_slot_rendered class=headerlink title="Permanent link">¤</a></h3> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=nf>on_slot_rendered</span><span class=p>(</span><span class=n>ctx</span><span class=p>:</span> <span class=n><span title=django_components.extension.OnSlotRenderedContext>OnSlotRenderedContext</span></span><span class=p>)</span> <span class=o>-&gt;</span> <span class=n><a class="autorefs autorefs-external" title=typing.Optional href=https://docs.python.org/3.12/library/typing.html#typing.Optional>Optional</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/stdtypes.html#str>str</a></span><span class=p>]</span> </code></pre></div> </div> </div><p><strong>Available data:</strong></p> <table> <thead> <tr> <th>name</th> <th>type</th> <th>description</th> </tr> </thead> <tbody> <tr> <td><code>registry</code></td> <td><a href=../api#django_components.ComponentRegistry><code>ComponentRegistry</code></a></td> <td>The to-be-deleted ComponentRegistry instance</td> </tr> </tbody> </table> <div class="doc doc-object doc-function"> <h3 id=django_components.extension.ComponentExtension.on_slot_rendered class="doc doc-heading"> <span class="doc doc-object-name doc-function-name">on_slot_rendered</span> <a href=#django_components.extension.ComponentExtension.on_slot_rendered class=headerlink title="Permanent link">¤</a></h3> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=nf>on_slot_rendered</span><span class=p>(</span><span class=n>ctx</span><span class=p>:</span> <span class=n><span title=django_components.extension.OnSlotRenderedContext>OnSlotRenderedContext</span></span><span class=p>)</span> <span class=o>-&gt;</span> <span class=n><a class="autorefs autorefs-external" title=typing.Optional href=https://docs.python.org/3.12/library/typing.html#typing.Optional>Optional</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/stdtypes.html#str>str</a></span><span class=p>]</span>
</code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/extension.py#L908 target=_blank>See source code</a></p> <p>Called when a <a href=../template_tags/#slot><code>{% slot %}</code></a> tag was rendered.</p> <p>Use this hook to access or post-process the slot's rendered output.</p> <p>To modify the output, return a new string from this hook.</p> <p><strong>Example:</strong></p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=kn>from</span><span class=w> </span><span class=nn>django_components</span><span class=w> </span><span class=kn>import</span> <span class=n>ComponentExtension</span><span class=p>,</span> <span class=n>OnSlotRenderedContext</span> </code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/extension.py#L895 target=_blank>See source code</a></p> <p>Called when a <a href=../template_tags/#slot><code>{% slot %}</code></a> tag was rendered.</p> <p>Use this hook to access or post-process the slot's rendered output.</p> <p>To modify the output, return a new string from this hook.</p> <p><strong>Example:</strong></p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=kn>from</span><span class=w> </span><span class=nn>django_components</span><span class=w> </span><span class=kn>import</span> <span class=n>ComponentExtension</span><span class=p>,</span> <span class=n>OnSlotRenderedContext</span>
<a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a> <a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a>
<a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a><span class=k>class</span><span class=w> </span><span class=nc>MyExtension</span><span class=p>(</span><span class=n>ComponentExtension</span><span class=p>):</span> <a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a><span class=k>class</span><span class=w> </span><span class=nc>MyExtension</span><span class=p>(</span><span class=n>ComponentExtension</span><span class=p>):</span>
<a id=__codelineno-0-4 name=__codelineno-0-4 href=#__codelineno-0-4></a> <span class=k>def</span><span class=w> </span><span class=nf>on_slot_rendered</span><span class=p>(</span><span class=bp>self</span><span class=p>,</span> <span class=n>ctx</span><span class=p>:</span> <span class=n>OnSlotRenderedContext</span><span class=p>)</span> <span class=o>-&gt;</span> <span class=n>Optional</span><span class=p>[</span><span class=nb>str</span><span class=p>]:</span> <a id=__codelineno-0-4 name=__codelineno-0-4 href=#__codelineno-0-4></a> <span class=k>def</span><span class=w> </span><span class=nf>on_slot_rendered</span><span class=p>(</span><span class=bp>self</span><span class=p>,</span> <span class=n>ctx</span><span class=p>:</span> <span class=n>OnSlotRenderedContext</span><span class=p>)</span> <span class=o>-&gt;</span> <span class=n>Optional</span><span class=p>[</span><span class=nb>str</span><span class=p>]:</span>
@ -219,13 +219,13 @@
<a id=__codelineno-1-7 name=__codelineno-1-7 href=#__codelineno-1-7></a> <span class=n>slot_owner</span> <span class=o>=</span> <span class=n>slot_node</span><span class=o>.</span><span class=n>template_component</span> <a id=__codelineno-1-7 name=__codelineno-1-7 href=#__codelineno-1-7></a> <span class=n>slot_owner</span> <span class=o>=</span> <span class=n>slot_node</span><span class=o>.</span><span class=n>template_component</span>
<a id=__codelineno-1-8 name=__codelineno-1-8 href=#__codelineno-1-8></a> <span class=nb>print</span><span class=p>(</span><span class=sa>f</span><span class=s2>&quot;Slot owner: </span><span class=si>{</span><span class=n>slot_owner</span><span class=si>}</span><span class=s2>&quot;</span><span class=p>)</span> <a id=__codelineno-1-8 name=__codelineno-1-8 href=#__codelineno-1-8></a> <span class=nb>print</span><span class=p>(</span><span class=sa>f</span><span class=s2>&quot;Slot owner: </span><span class=si>{</span><span class=n>slot_owner</span><span class=si>}</span><span class=s2>&quot;</span><span class=p>)</span>
</code></pre></div> </div> </div><p><strong>Available data:</strong></p> <table> <thead> <tr> <th>name</th> <th>type</th> <th>description</th> </tr> </thead> <tbody> <tr> <td><code>component</code></td> <td><a href=../api#django_components.Component><code>Component</code></a></td> <td>The Component instance that contains the <code>{% slot %}</code> tag</td> </tr> <tr> <td><code>component_cls</code></td> <td><a href=../api#django_components.Component><code>Type[Component]</code></a></td> <td>The Component class that contains the <code>{% slot %}</code> tag</td> </tr> <tr> <td><code>component_id</code></td> <td><code>str</code></td> <td>The unique identifier for this component instance</td> </tr> <tr> <td><code>result</code></td> <td><code>SlotResult</code></td> <td>The rendered result of the slot</td> </tr> <tr> <td><code>slot</code></td> <td><code>Slot</code></td> <td>The Slot instance that was rendered</td> </tr> <tr> <td><code>slot_is_default</code></td> <td><code>bool</code></td> <td>Whether the slot is default</td> </tr> <tr> <td><code>slot_is_required</code></td> <td><code>bool</code></td> <td>Whether the slot is required</td> </tr> <tr> <td><code>slot_name</code></td> <td><code>str</code></td> <td>The name of the <code>{% slot %}</code> tag</td> </tr> <tr> <td><code>slot_node</code></td> <td><code>SlotNode</code></td> <td>The node instance of the <code>{% slot %}</code> tag</td> </tr> </tbody> </table> <div class="doc doc-object doc-function"> <h3 id=django_components.extension.ComponentExtension.on_template_compiled class="doc doc-heading"> <span class="doc doc-object-name doc-function-name">on_template_compiled</span> <a href=#django_components.extension.ComponentExtension.on_template_compiled class=headerlink title="Permanent link">¤</a></h3> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=nf>on_template_compiled</span><span class=p>(</span><span class=n>ctx</span><span class=p>:</span> <span class=n><span title=django_components.extension.OnTemplateCompiledContext>OnTemplateCompiledContext</span></span><span class=p>)</span> <span class=o>-&gt;</span> <span class=kc>None</span> </code></pre></div> </div> </div><p><strong>Available data:</strong></p> <table> <thead> <tr> <th>name</th> <th>type</th> <th>description</th> </tr> </thead> <tbody> <tr> <td><code>component</code></td> <td><a href=../api#django_components.Component><code>Component</code></a></td> <td>The Component instance that contains the <code>{% slot %}</code> tag</td> </tr> <tr> <td><code>component_cls</code></td> <td><a href=../api#django_components.Component><code>Type[Component]</code></a></td> <td>The Component class that contains the <code>{% slot %}</code> tag</td> </tr> <tr> <td><code>component_id</code></td> <td><code>str</code></td> <td>The unique identifier for this component instance</td> </tr> <tr> <td><code>result</code></td> <td><code>SlotResult</code></td> <td>The rendered result of the slot</td> </tr> <tr> <td><code>slot</code></td> <td><code>Slot</code></td> <td>The Slot instance that was rendered</td> </tr> <tr> <td><code>slot_is_default</code></td> <td><code>bool</code></td> <td>Whether the slot is default</td> </tr> <tr> <td><code>slot_is_required</code></td> <td><code>bool</code></td> <td>Whether the slot is required</td> </tr> <tr> <td><code>slot_name</code></td> <td><code>str</code></td> <td>The name of the <code>{% slot %}</code> tag</td> </tr> <tr> <td><code>slot_node</code></td> <td><code>SlotNode</code></td> <td>The node instance of the <code>{% slot %}</code> tag</td> </tr> </tbody> </table> <div class="doc doc-object doc-function"> <h3 id=django_components.extension.ComponentExtension.on_template_compiled class="doc doc-heading"> <span class="doc doc-object-name doc-function-name">on_template_compiled</span> <a href=#django_components.extension.ComponentExtension.on_template_compiled class=headerlink title="Permanent link">¤</a></h3> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=nf>on_template_compiled</span><span class=p>(</span><span class=n>ctx</span><span class=p>:</span> <span class=n><span title=django_components.extension.OnTemplateCompiledContext>OnTemplateCompiledContext</span></span><span class=p>)</span> <span class=o>-&gt;</span> <span class=kc>None</span>
</code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/extension.py#L831 target=_blank>See source code</a></p> <p>Called when a Component's template is compiled into a <a href=https://docs.djangoproject.com/en/5.2/ref/templates/api/#django.template.Template><code>Template</code></a> object.</p> <p>This hook runs only once per <a href=../api/#django_components.Component><code>Component</code></a> class and works for both <a href=../api/#django_components.Component.template><code>Component.template</code></a> and <a href=../api/#django_components.Component.template_file><code>Component.template_file</code></a>.</p> <p>Use this hook to read or modify the template (in-place) after it's compiled.</p> <p><strong>Example:</strong></p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=kn>from</span><span class=w> </span><span class=nn>django_components</span><span class=w> </span><span class=kn>import</span> <span class=n>ComponentExtension</span><span class=p>,</span> <span class=n>OnTemplateCompiledContext</span> </code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/extension.py#L821 target=_blank>See source code</a></p> <p>Called when a Component's template is compiled into a <a href=https://docs.djangoproject.com/en/5.2/ref/templates/api/#django.template.Template><code>Template</code></a> object.</p> <p>This hook runs only once per <a href=../api/#django_components.Component><code>Component</code></a> class and works for both <a href=../api/#django_components.Component.template><code>Component.template</code></a> and <a href=../api/#django_components.Component.template_file><code>Component.template_file</code></a>.</p> <p>Use this hook to read or modify the template (in-place) after it's compiled.</p> <p><strong>Example:</strong></p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=kn>from</span><span class=w> </span><span class=nn>django_components</span><span class=w> </span><span class=kn>import</span> <span class=n>ComponentExtension</span><span class=p>,</span> <span class=n>OnTemplateCompiledContext</span>
<a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a> <a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a>
<a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a><span class=k>class</span><span class=w> </span><span class=nc>MyExtension</span><span class=p>(</span><span class=n>ComponentExtension</span><span class=p>):</span> <a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a><span class=k>class</span><span class=w> </span><span class=nc>MyExtension</span><span class=p>(</span><span class=n>ComponentExtension</span><span class=p>):</span>
<a id=__codelineno-0-4 name=__codelineno-0-4 href=#__codelineno-0-4></a> <span class=k>def</span><span class=w> </span><span class=nf>on_template_compiled</span><span class=p>(</span><span class=bp>self</span><span class=p>,</span> <span class=n>ctx</span><span class=p>:</span> <span class=n>OnTemplateCompiledContext</span><span class=p>)</span> <span class=o>-&gt;</span> <span class=kc>None</span><span class=p>:</span> <a id=__codelineno-0-4 name=__codelineno-0-4 href=#__codelineno-0-4></a> <span class=k>def</span><span class=w> </span><span class=nf>on_template_compiled</span><span class=p>(</span><span class=bp>self</span><span class=p>,</span> <span class=n>ctx</span><span class=p>:</span> <span class=n>OnTemplateCompiledContext</span><span class=p>)</span> <span class=o>-&gt;</span> <span class=kc>None</span><span class=p>:</span>
<a id=__codelineno-0-5 name=__codelineno-0-5 href=#__codelineno-0-5></a> <span class=nb>print</span><span class=p>(</span><span class=sa>f</span><span class=s2>&quot;Template origin: </span><span class=si>{</span><span class=n>ctx</span><span class=o>.</span><span class=n>template</span><span class=o>.</span><span class=n>origin</span><span class=o>.</span><span class=n>name</span><span class=si>}</span><span class=s2>&quot;</span><span class=p>)</span> <a id=__codelineno-0-5 name=__codelineno-0-5 href=#__codelineno-0-5></a> <span class=nb>print</span><span class=p>(</span><span class=sa>f</span><span class=s2>&quot;Template origin: </span><span class=si>{</span><span class=n>ctx</span><span class=o>.</span><span class=n>template</span><span class=o>.</span><span class=n>origin</span><span class=o>.</span><span class=n>name</span><span class=si>}</span><span class=s2>&quot;</span><span class=p>)</span>
</code></pre></div> </div> </div><p><strong>Available data:</strong></p> <table> <thead> <tr> <th>name</th> <th>type</th> <th>description</th> </tr> </thead> <tbody> <tr> <td><code>component_cls</code></td> <td><a href=../api#django_components.Component><code>Type[Component]</code></a></td> <td>The Component class whose template was loaded</td> </tr> <tr> <td><code>template</code></td> <td><code>django.template.base.Template</code></td> <td>The compiled template object</td> </tr> </tbody> </table> <div class="doc doc-object doc-function"> <h3 id=django_components.extension.ComponentExtension.on_template_loaded class="doc doc-heading"> <span class="doc doc-object-name doc-function-name">on_template_loaded</span> <a href=#django_components.extension.ComponentExtension.on_template_loaded class=headerlink title="Permanent link">¤</a></h3> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=nf>on_template_loaded</span><span class=p>(</span><span class=n>ctx</span><span class=p>:</span> <span class=n><span title=django_components.extension.OnTemplateLoadedContext>OnTemplateLoadedContext</span></span><span class=p>)</span> <span class=o>-&gt;</span> <span class=n><a class="autorefs autorefs-external" title=typing.Optional href=https://docs.python.org/3.12/library/typing.html#typing.Optional>Optional</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/stdtypes.html#str>str</a></span><span class=p>]</span> </code></pre></div> </div> </div><p><strong>Available data:</strong></p> <table> <thead> <tr> <th>name</th> <th>type</th> <th>description</th> </tr> </thead> <tbody> <tr> <td><code>component_cls</code></td> <td><a href=../api#django_components.Component><code>Type[Component]</code></a></td> <td>The Component class whose template was loaded</td> </tr> <tr> <td><code>template</code></td> <td><code>django.template.base.Template</code></td> <td>The compiled template object</td> </tr> </tbody> </table> <div class="doc doc-object doc-function"> <h3 id=django_components.extension.ComponentExtension.on_template_loaded class="doc doc-heading"> <span class="doc doc-object-name doc-function-name">on_template_loaded</span> <a href=#django_components.extension.ComponentExtension.on_template_loaded class=headerlink title="Permanent link">¤</a></h3> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=nf>on_template_loaded</span><span class=p>(</span><span class=n>ctx</span><span class=p>:</span> <span class=n><span title=django_components.extension.OnTemplateLoadedContext>OnTemplateLoadedContext</span></span><span class=p>)</span> <span class=o>-&gt;</span> <span class=n><a class="autorefs autorefs-external" title=typing.Optional href=https://docs.python.org/3.12/library/typing.html#typing.Optional>Optional</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/stdtypes.html#str>str</a></span><span class=p>]</span>
</code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/extension.py#L806 target=_blank>See source code</a></p> <p>Called when a Component's template is loaded as a string.</p> <p>This hook runs only once per <a href=../api/#django_components.Component><code>Component</code></a> class and works for both <a href=../api/#django_components.Component.template><code>Component.template</code></a> and <a href=../api/#django_components.Component.template_file><code>Component.template_file</code></a>.</p> <p>Use this hook to read or modify the template before it's compiled.</p> <p>To modify the template, return a new string from this hook.</p> <p><strong>Example:</strong></p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=kn>from</span><span class=w> </span><span class=nn>django_components</span><span class=w> </span><span class=kn>import</span> <span class=n>ComponentExtension</span><span class=p>,</span> <span class=n>OnTemplateLoadedContext</span> </code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/extension.py#L797 target=_blank>See source code</a></p> <p>Called when a Component's template is loaded as a string.</p> <p>This hook runs only once per <a href=../api/#django_components.Component><code>Component</code></a> class and works for both <a href=../api/#django_components.Component.template><code>Component.template</code></a> and <a href=../api/#django_components.Component.template_file><code>Component.template_file</code></a>.</p> <p>Use this hook to read or modify the template before it's compiled.</p> <p>To modify the template, return a new string from this hook.</p> <p><strong>Example:</strong></p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=kn>from</span><span class=w> </span><span class=nn>django_components</span><span class=w> </span><span class=kn>import</span> <span class=n>ComponentExtension</span><span class=p>,</span> <span class=n>OnTemplateLoadedContext</span>
<a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a> <a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a>
<a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a><span class=k>class</span><span class=w> </span><span class=nc>MyExtension</span><span class=p>(</span><span class=n>ComponentExtension</span><span class=p>):</span> <a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a><span class=k>class</span><span class=w> </span><span class=nc>MyExtension</span><span class=p>(</span><span class=n>ComponentExtension</span><span class=p>):</span>
<a id=__codelineno-0-4 name=__codelineno-0-4 href=#__codelineno-0-4></a> <span class=k>def</span><span class=w> </span><span class=nf>on_template_loaded</span><span class=p>(</span><span class=bp>self</span><span class=p>,</span> <span class=n>ctx</span><span class=p>:</span> <span class=n>OnTemplateLoadedContext</span><span class=p>)</span> <span class=o>-&gt;</span> <span class=n>Optional</span><span class=p>[</span><span class=nb>str</span><span class=p>]:</span> <a id=__codelineno-0-4 name=__codelineno-0-4 href=#__codelineno-0-4></a> <span class=k>def</span><span class=w> </span><span class=nf>on_template_loaded</span><span class=p>(</span><span class=bp>self</span><span class=p>,</span> <span class=n>ctx</span><span class=p>:</span> <span class=n>OnTemplateLoadedContext</span><span class=p>)</span> <span class=o>-&gt;</span> <span class=n>Optional</span><span class=p>[</span><span class=nb>str</span><span class=p>]:</span>

File diff suppressed because one or more lines are too long

View file

@ -162,41 +162,41 @@
<a id=__codelineno-1-34 name=__codelineno-1-34 href=#__codelineno-1-34></a> <span class=n>template_cache_size</span><span class=o>=</span><span class=mi>128</span><span class=p>,</span> <a id=__codelineno-1-34 name=__codelineno-1-34 href=#__codelineno-1-34></a> <span class=n>template_cache_size</span><span class=o>=</span><span class=mi>128</span><span class=p>,</span>
<a id=__codelineno-1-35 name=__codelineno-1-35 href=#__codelineno-1-35></a><span class=p>)</span> <a id=__codelineno-1-35 name=__codelineno-1-35 href=#__codelineno-1-35></a><span class=p>)</span>
</code></pre></div> <div class="doc doc-object doc-attribute"> <h2 id=django_components.app_settings.ComponentsSettings.app_dirs class="doc doc-heading"> <span class="doc doc-object-name doc-attribute-name">app_dirs</span> <a href=#django_components.app_settings.ComponentsSettings.app_dirs class=headerlink title="Permanent link">¤</a></h2> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>app_dirs</span><span class=p>:</span> <span class=n><a class="autorefs autorefs-external" title=typing.Optional href=https://docs.python.org/3.12/library/typing.html#typing.Optional>Optional</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" title=typing.Sequence href=https://docs.python.org/3.12/library/typing.html#typing.Sequence>Sequence</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/stdtypes.html#str>str</a></span><span class=p>]]</span> <span class=o>=</span> <span class=kc>None</span> </code></pre></div> <div class="doc doc-object doc-attribute"> <h2 id=django_components.app_settings.ComponentsSettings.app_dirs class="doc doc-heading"> <span class="doc doc-object-name doc-attribute-name">app_dirs</span> <a href=#django_components.app_settings.ComponentsSettings.app_dirs class=headerlink title="Permanent link">¤</a></h2> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>app_dirs</span><span class=p>:</span> <span class=n><a class="autorefs autorefs-external" title=typing.Optional href=https://docs.python.org/3.12/library/typing.html#typing.Optional>Optional</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" title=typing.Sequence href=https://docs.python.org/3.12/library/typing.html#typing.Sequence>Sequence</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/stdtypes.html#str>str</a></span><span class=p>]]</span> <span class=o>=</span> <span class=kc>None</span>
</code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/app_settings.py#L238 target=_blank>See source code</a></p> <p>Specify the app-level directories that contain your components.</p> <p>Defaults to <code>["components"]</code>. That is, for each Django app, we search <code>&lt;app&gt;/components/</code> for components.</p> <p>The paths must be relative to app, e.g.:</p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>COMPONENTS</span> <span class=o>=</span> <span class=n>ComponentsSettings</span><span class=p>(</span> </code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/app_settings.py#L239 target=_blank>See source code</a></p> <p>Specify the app-level directories that contain your components.</p> <p>Defaults to <code>["components"]</code>. That is, for each Django app, we search <code>&lt;app&gt;/components/</code> for components.</p> <p>The paths must be relative to app, e.g.:</p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>COMPONENTS</span> <span class=o>=</span> <span class=n>ComponentsSettings</span><span class=p>(</span>
<a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a> <span class=n>app_dirs</span><span class=o>=</span><span class=p>[</span><span class=s2>&quot;my_comps&quot;</span><span class=p>],</span> <a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a> <span class=n>app_dirs</span><span class=o>=</span><span class=p>[</span><span class=s2>&quot;my_comps&quot;</span><span class=p>],</span>
<a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a><span class=p>)</span> <a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a><span class=p>)</span>
</code></pre></div> <p>To search for <code>&lt;app&gt;/my_comps/</code>.</p> <p>These locations are searched during <a href=../../concepts/fundamentals/autodiscovery/ >autodiscovery</a>, or when you <a href=../../concepts/fundamentals/html_js_css_files/ >define HTML, JS, or CSS as separate files</a>.</p> <p>Set to empty list to disable app-level components:</p> <div class=highlight><pre><span></span><code><a id=__codelineno-1-1 name=__codelineno-1-1 href=#__codelineno-1-1></a><span class=n>COMPONENTS</span> <span class=o>=</span> <span class=n>ComponentsSettings</span><span class=p>(</span> </code></pre></div> <p>To search for <code>&lt;app&gt;/my_comps/</code>.</p> <p>These locations are searched during <a href=../../concepts/fundamentals/autodiscovery/ >autodiscovery</a>, or when you <a href=../../concepts/fundamentals/html_js_css_files/ >define HTML, JS, or CSS as separate files</a>.</p> <p>Set to empty list to disable app-level components:</p> <div class=highlight><pre><span></span><code><a id=__codelineno-1-1 name=__codelineno-1-1 href=#__codelineno-1-1></a><span class=n>COMPONENTS</span> <span class=o>=</span> <span class=n>ComponentsSettings</span><span class=p>(</span>
<a id=__codelineno-1-2 name=__codelineno-1-2 href=#__codelineno-1-2></a> <span class=n>app_dirs</span><span class=o>=</span><span class=p>[],</span> <a id=__codelineno-1-2 name=__codelineno-1-2 href=#__codelineno-1-2></a> <span class=n>app_dirs</span><span class=o>=</span><span class=p>[],</span>
<a id=__codelineno-1-3 name=__codelineno-1-3 href=#__codelineno-1-3></a><span class=p>)</span> <a id=__codelineno-1-3 name=__codelineno-1-3 href=#__codelineno-1-3></a><span class=p>)</span>
</code></pre></div> </div> </div> <div class="doc doc-object doc-attribute"> <h2 id=django_components.app_settings.ComponentsSettings.autodiscover class="doc doc-heading"> <span class="doc doc-object-name doc-attribute-name">autodiscover</span> <a href=#django_components.app_settings.ComponentsSettings.autodiscover class=headerlink title="Permanent link">¤</a></h2> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>autodiscover</span><span class=p>:</span> <span class=n><a class="autorefs autorefs-external" title=typing.Optional href=https://docs.python.org/3.12/library/typing.html#typing.Optional>Optional</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/functions.html#bool>bool</a></span><span class=p>]</span> <span class=o>=</span> <span class=kc>None</span> </code></pre></div> </div> </div> <div class="doc doc-object doc-attribute"> <h2 id=django_components.app_settings.ComponentsSettings.autodiscover class="doc doc-heading"> <span class="doc doc-object-name doc-attribute-name">autodiscover</span> <a href=#django_components.app_settings.ComponentsSettings.autodiscover class=headerlink title="Permanent link">¤</a></h2> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>autodiscover</span><span class=p>:</span> <span class=n><a class="autorefs autorefs-external" title=typing.Optional href=https://docs.python.org/3.12/library/typing.html#typing.Optional>Optional</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/functions.html#bool>bool</a></span><span class=p>]</span> <span class=o>=</span> <span class=kc>None</span>
</code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/app_settings.py#L198 target=_blank>See source code</a></p> <p>Toggle whether to run <a href=../../concepts/fundamentals/autodiscovery/ >autodiscovery</a> at the Django server startup.</p> <p>Defaults to <code>True</code></p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>COMPONENTS</span> <span class=o>=</span> <span class=n>ComponentsSettings</span><span class=p>(</span> </code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/app_settings.py#L199 target=_blank>See source code</a></p> <p>Toggle whether to run <a href=../../concepts/fundamentals/autodiscovery/ >autodiscovery</a> at the Django server startup.</p> <p>Defaults to <code>True</code></p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>COMPONENTS</span> <span class=o>=</span> <span class=n>ComponentsSettings</span><span class=p>(</span>
<a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a> <span class=n>autodiscover</span><span class=o>=</span><span class=kc>False</span><span class=p>,</span> <a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a> <span class=n>autodiscover</span><span class=o>=</span><span class=kc>False</span><span class=p>,</span>
<a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a><span class=p>)</span> <a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a><span class=p>)</span>
</code></pre></div> </div> </div> <div class="doc doc-object doc-attribute"> <h2 id=django_components.app_settings.ComponentsSettings.cache class="doc doc-heading"> <span class="doc doc-object-name doc-attribute-name">cache</span> <a href=#django_components.app_settings.ComponentsSettings.cache class=headerlink title="Permanent link">¤</a></h2> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>cache</span><span class=p>:</span> <span class=n><a class="autorefs autorefs-external" title=typing.Optional href=https://docs.python.org/3.12/library/typing.html#typing.Optional>Optional</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/stdtypes.html#str>str</a></span><span class=p>]</span> <span class=o>=</span> <span class=kc>None</span> </code></pre></div> </div> </div> <div class="doc doc-object doc-attribute"> <h2 id=django_components.app_settings.ComponentsSettings.cache class="doc doc-heading"> <span class="doc doc-object-name doc-attribute-name">cache</span> <a href=#django_components.app_settings.ComponentsSettings.cache class=headerlink title="Permanent link">¤</a></h2> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>cache</span><span class=p>:</span> <span class=n><a class="autorefs autorefs-external" title=typing.Optional href=https://docs.python.org/3.12/library/typing.html#typing.Optional>Optional</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/stdtypes.html#str>str</a></span><span class=p>]</span> <span class=o>=</span> <span class=kc>None</span>
</code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/app_settings.py#L266 target=_blank>See source code</a></p> <p>Name of the <a href=https://docs.djangoproject.com/en/5.2/topics/cache/ >Django cache</a> to be used for storing component's JS and CSS files.</p> <p>If <code>None</code>, a <a href=https://docs.djangoproject.com/en/5.2/topics/cache/#local-memory-caching><code>LocMemCache</code></a> is used with default settings.</p> <p>Defaults to <code>None</code>.</p> <p>Read more about <a href=../../guides/setup/caching/ >caching</a>.</p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>COMPONENTS</span> <span class=o>=</span> <span class=n>ComponentsSettings</span><span class=p>(</span> </code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/app_settings.py#L267 target=_blank>See source code</a></p> <p>Name of the <a href=https://docs.djangoproject.com/en/5.2/topics/cache/ >Django cache</a> to be used for storing component's JS and CSS files.</p> <p>If <code>None</code>, a <a href=https://docs.djangoproject.com/en/5.2/topics/cache/#local-memory-caching><code>LocMemCache</code></a> is used with default settings.</p> <p>Defaults to <code>None</code>.</p> <p>Read more about <a href=../../guides/setup/caching/ >caching</a>.</p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>COMPONENTS</span> <span class=o>=</span> <span class=n>ComponentsSettings</span><span class=p>(</span>
<a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a> <span class=n>cache</span><span class=o>=</span><span class=s2>&quot;my_cache&quot;</span><span class=p>,</span> <a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a> <span class=n>cache</span><span class=o>=</span><span class=s2>&quot;my_cache&quot;</span><span class=p>,</span>
<a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a><span class=p>)</span> <a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a><span class=p>)</span>
</code></pre></div> </div> </div> <div class="doc doc-object doc-attribute"> <h2 id=django_components.app_settings.ComponentsSettings.context_behavior class="doc doc-heading"> <span class="doc doc-object-name doc-attribute-name">context_behavior</span> <a href=#django_components.app_settings.ComponentsSettings.context_behavior class=headerlink title="Permanent link">¤</a></h2> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>context_behavior</span><span class=p>:</span> <span class=n><a class="autorefs autorefs-external" title=typing.Optional href=https://docs.python.org/3.12/library/typing.html#typing.Optional>Optional</a></span><span class=p>[</span><span class=n><span title=django_components.app_settings.ContextBehaviorType>ContextBehaviorType</span></span><span class=p>]</span> <span class=o>=</span> <span class=kc>None</span> </code></pre></div> </div> </div> <div class="doc doc-object doc-attribute"> <h2 id=django_components.app_settings.ComponentsSettings.context_behavior class="doc doc-heading"> <span class="doc doc-object-name doc-attribute-name">context_behavior</span> <a href=#django_components.app_settings.ComponentsSettings.context_behavior class=headerlink title="Permanent link">¤</a></h2> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>context_behavior</span><span class=p>:</span> <span class=n><a class="autorefs autorefs-external" title=typing.Optional href=https://docs.python.org/3.12/library/typing.html#typing.Optional>Optional</a></span><span class=p>[</span><span class=n><span title=django_components.app_settings.ContextBehaviorType>ContextBehaviorType</span></span><span class=p>]</span> <span class=o>=</span> <span class=kc>None</span>
</code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/app_settings.py#L285 target=_blank>See source code</a></p> <p>Configure whether, inside a component template, you can use variables from the outside (<a href=../api/#django_components.ContextBehavior.DJANGO><code>"django"</code></a>) or not (<a href=../api/#django_components.ContextBehavior.ISOLATED><code>"isolated"</code></a>). This also affects what variables are available inside the <a href=../template_tags/#fill><code>{% fill %}</code></a> tags.</p> <p>Also see <a href=../../concepts/advanced/component_context_scope/#context-behavior>Component context and scope</a>.</p> <p>Defaults to <code>"django"</code>.</p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>COMPONENTS</span> <span class=o>=</span> <span class=n>ComponentsSettings</span><span class=p>(</span> </code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/app_settings.py#L286 target=_blank>See source code</a></p> <p>Configure whether, inside a component template, you can use variables from the outside (<a href=../api/#django_components.ContextBehavior.DJANGO><code>"django"</code></a>) or not (<a href=../api/#django_components.ContextBehavior.ISOLATED><code>"isolated"</code></a>). This also affects what variables are available inside the <a href=../template_tags/#fill><code>{% fill %}</code></a> tags.</p> <p>Also see <a href=../../concepts/advanced/component_context_scope/#context-behavior>Component context and scope</a>.</p> <p>Defaults to <code>"django"</code>.</p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>COMPONENTS</span> <span class=o>=</span> <span class=n>ComponentsSettings</span><span class=p>(</span>
<a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a> <span class=n>context_behavior</span><span class=o>=</span><span class=s2>&quot;isolated&quot;</span><span class=p>,</span> <a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a> <span class=n>context_behavior</span><span class=o>=</span><span class=s2>&quot;isolated&quot;</span><span class=p>,</span>
<a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a><span class=p>)</span> <a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a><span class=p>)</span>
</code></pre></div> <blockquote> <p>NOTE: <code>context_behavior</code> and <code>slot_context_behavior</code> options were merged in v0.70.</p> <p>If you are migrating from BEFORE v0.67, set <code>context_behavior</code> to <code>"django"</code>. From v0.67 to v0.78 (incl) the default value was <code>"isolated"</code>.</p> <p>For v0.79 and later, the default is again <code>"django"</code>. See the rationale for change <a href=https://github.com/django-components/django-components/issues/498>here</a>.</p> </blockquote> </div> </div> <div class="doc doc-object doc-attribute"> <h2 id=django_components.app_settings.ComponentsSettings.debug_highlight_components class="doc doc-heading"> <span class="doc doc-object-name doc-attribute-name">debug_highlight_components</span> <a href=#django_components.app_settings.ComponentsSettings.debug_highlight_components class=headerlink title="Permanent link">¤</a></h2> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>debug_highlight_components</span><span class=p>:</span> <span class=n><a class="autorefs autorefs-external" title=typing.Optional href=https://docs.python.org/3.12/library/typing.html#typing.Optional>Optional</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/functions.html#bool>bool</a></span><span class=p>]</span> <span class=o>=</span> <span class=kc>None</span> </code></pre></div> <blockquote> <p>NOTE: <code>context_behavior</code> and <code>slot_context_behavior</code> options were merged in v0.70.</p> <p>If you are migrating from BEFORE v0.67, set <code>context_behavior</code> to <code>"django"</code>. From v0.67 to v0.78 (incl) the default value was <code>"isolated"</code>.</p> <p>For v0.79 and later, the default is again <code>"django"</code>. See the rationale for change <a href=https://github.com/django-components/django-components/issues/498>here</a>.</p> </blockquote> </div> </div> <div class="doc doc-object doc-attribute"> <h2 id=django_components.app_settings.ComponentsSettings.debug_highlight_components class="doc doc-heading"> <span class="doc doc-object-name doc-attribute-name">debug_highlight_components</span> <a href=#django_components.app_settings.ComponentsSettings.debug_highlight_components class=headerlink title="Permanent link">¤</a></h2> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>debug_highlight_components</span><span class=p>:</span> <span class=n><a class="autorefs autorefs-external" title=typing.Optional href=https://docs.python.org/3.12/library/typing.html#typing.Optional>Optional</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/functions.html#bool>bool</a></span><span class=p>]</span> <span class=o>=</span> <span class=kc>None</span>
</code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/app_settings.py#L313 target=_blank>See source code</a></p> <p>DEPRECATED. Use <a href=./#django_components.app_settings.ComponentsSettings.extensions_defaults><code>extensions_defaults</code></a> instead. Will be removed in v1.</p> <p>Enable / disable component highlighting. See <a href=../../guides/other/troubleshooting/#component-and-slot-highlighting>Troubleshooting</a> for more details.</p> <p>Defaults to <code>False</code>.</p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>COMPONENTS</span> <span class=o>=</span> <span class=n>ComponentsSettings</span><span class=p>(</span> </code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/app_settings.py#L314 target=_blank>See source code</a></p> <p>DEPRECATED. Use <a href=./#django_components.app_settings.ComponentsSettings.extensions_defaults><code>extensions_defaults</code></a> instead. Will be removed in v1.</p> <p>Enable / disable component highlighting. See <a href=../../guides/other/troubleshooting/#component-and-slot-highlighting>Troubleshooting</a> for more details.</p> <p>Defaults to <code>False</code>.</p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>COMPONENTS</span> <span class=o>=</span> <span class=n>ComponentsSettings</span><span class=p>(</span>
<a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a> <span class=n>debug_highlight_components</span><span class=o>=</span><span class=kc>True</span><span class=p>,</span> <a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a> <span class=n>debug_highlight_components</span><span class=o>=</span><span class=kc>True</span><span class=p>,</span>
<a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a><span class=p>)</span> <a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a><span class=p>)</span>
</code></pre></div> </div> </div> <div class="doc doc-object doc-attribute"> <h2 id=django_components.app_settings.ComponentsSettings.debug_highlight_slots class="doc doc-heading"> <span class="doc doc-object-name doc-attribute-name">debug_highlight_slots</span> <a href=#django_components.app_settings.ComponentsSettings.debug_highlight_slots class=headerlink title="Permanent link">¤</a></h2> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>debug_highlight_slots</span><span class=p>:</span> <span class=n><a class="autorefs autorefs-external" title=typing.Optional href=https://docs.python.org/3.12/library/typing.html#typing.Optional>Optional</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/functions.html#bool>bool</a></span><span class=p>]</span> <span class=o>=</span> <span class=kc>None</span> </code></pre></div> </div> </div> <div class="doc doc-object doc-attribute"> <h2 id=django_components.app_settings.ComponentsSettings.debug_highlight_slots class="doc doc-heading"> <span class="doc doc-object-name doc-attribute-name">debug_highlight_slots</span> <a href=#django_components.app_settings.ComponentsSettings.debug_highlight_slots class=headerlink title="Permanent link">¤</a></h2> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>debug_highlight_slots</span><span class=p>:</span> <span class=n><a class="autorefs autorefs-external" title=typing.Optional href=https://docs.python.org/3.12/library/typing.html#typing.Optional>Optional</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/functions.html#bool>bool</a></span><span class=p>]</span> <span class=o>=</span> <span class=kc>None</span>
</code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/app_settings.py#L332 target=_blank>See source code</a></p> <p>DEPRECATED. Use <a href=./#django_components.app_settings.ComponentsSettings.extensions_defaults><code>extensions_defaults</code></a> instead. Will be removed in v1.</p> <p>Enable / disable slot highlighting. See <a href=../../guides/other/troubleshooting/#component-and-slot-highlighting>Troubleshooting</a> for more details.</p> <p>Defaults to <code>False</code>.</p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>COMPONENTS</span> <span class=o>=</span> <span class=n>ComponentsSettings</span><span class=p>(</span> </code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/app_settings.py#L333 target=_blank>See source code</a></p> <p>DEPRECATED. Use <a href=./#django_components.app_settings.ComponentsSettings.extensions_defaults><code>extensions_defaults</code></a> instead. Will be removed in v1.</p> <p>Enable / disable slot highlighting. See <a href=../../guides/other/troubleshooting/#component-and-slot-highlighting>Troubleshooting</a> for more details.</p> <p>Defaults to <code>False</code>.</p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>COMPONENTS</span> <span class=o>=</span> <span class=n>ComponentsSettings</span><span class=p>(</span>
<a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a> <span class=n>debug_highlight_slots</span><span class=o>=</span><span class=kc>True</span><span class=p>,</span> <a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a> <span class=n>debug_highlight_slots</span><span class=o>=</span><span class=kc>True</span><span class=p>,</span>
<a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a><span class=p>)</span> <a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a><span class=p>)</span>
</code></pre></div> </div> </div> <div class="doc doc-object doc-attribute"> <h2 id=django_components.app_settings.ComponentsSettings.dirs class="doc doc-heading"> <span class="doc doc-object-name doc-attribute-name">dirs</span> <a href=#django_components.app_settings.ComponentsSettings.dirs class=headerlink title="Permanent link">¤</a></h2> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>dirs</span><span class=p>:</span> <span class=n><a class="autorefs autorefs-external" title=typing.Optional href=https://docs.python.org/3.12/library/typing.html#typing.Optional>Optional</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" title=typing.Sequence href=https://docs.python.org/3.12/library/typing.html#typing.Sequence>Sequence</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" title=typing.Union href=https://docs.python.org/3.12/library/typing.html#typing.Union>Union</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/stdtypes.html#str>str</a></span><span class=p>,</span> <span class=n><a class="autorefs autorefs-external" title=os.PathLike href=https://docs.python.org/3.12/library/os.html#os.PathLike>PathLike</a></span><span class=p>,</span> <span class=n><a class="autorefs autorefs-external" title=typing.Tuple href=https://docs.python.org/3.12/library/typing.html#typing.Tuple>Tuple</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/stdtypes.html#str>str</a></span><span class=p>,</span> <span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/stdtypes.html#str>str</a></span><span class=p>],</span> <span class=n><a class="autorefs autorefs-external" title=typing.Tuple href=https://docs.python.org/3.12/library/typing.html#typing.Tuple>Tuple</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/stdtypes.html#str>str</a></span><span class=p>,</span> <span class=n><a class="autorefs autorefs-external" title=os.PathLike href=https://docs.python.org/3.12/library/os.html#os.PathLike>PathLike</a></span><span class=p>]]]]</span> <span class=o>=</span> <span class=kc>None</span> </code></pre></div> </div> </div> <div class="doc doc-object doc-attribute"> <h2 id=django_components.app_settings.ComponentsSettings.dirs class="doc doc-heading"> <span class="doc doc-object-name doc-attribute-name">dirs</span> <a href=#django_components.app_settings.ComponentsSettings.dirs class=headerlink title="Permanent link">¤</a></h2> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>dirs</span><span class=p>:</span> <span class=n><a class="autorefs autorefs-external" title=typing.Optional href=https://docs.python.org/3.12/library/typing.html#typing.Optional>Optional</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" title=typing.Sequence href=https://docs.python.org/3.12/library/typing.html#typing.Sequence>Sequence</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" title=typing.Union href=https://docs.python.org/3.12/library/typing.html#typing.Union>Union</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/stdtypes.html#str>str</a></span><span class=p>,</span> <span class=n><a class="autorefs autorefs-external" title=os.PathLike href=https://docs.python.org/3.12/library/os.html#os.PathLike>PathLike</a></span><span class=p>,</span> <span class=n><a class="autorefs autorefs-external" title=typing.Tuple href=https://docs.python.org/3.12/library/typing.html#typing.Tuple>Tuple</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/stdtypes.html#str>str</a></span><span class=p>,</span> <span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/stdtypes.html#str>str</a></span><span class=p>],</span> <span class=n><a class="autorefs autorefs-external" title=typing.Tuple href=https://docs.python.org/3.12/library/typing.html#typing.Tuple>Tuple</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/stdtypes.html#str>str</a></span><span class=p>,</span> <span class=n><a class="autorefs autorefs-external" title=os.PathLike href=https://docs.python.org/3.12/library/os.html#os.PathLike>PathLike</a></span><span class=p>]]]]</span> <span class=o>=</span> <span class=kc>None</span>
</code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/app_settings.py#L211 target=_blank>See source code</a></p> <p>Specify the directories that contain your components.</p> <p>Defaults to <code>[Path(settings.BASE_DIR) / "components"]</code>. That is, the root <code>components/</code> app.</p> <p>Directories must be full paths, same as with <a href=https://docs.djangoproject.com/en/5.2/ref/settings/#std-setting-STATICFILES_DIRS>STATICFILES_DIRS</a>.</p> <p>These locations are searched during <a href=../../concepts/fundamentals/autodiscovery/ >autodiscovery</a>, or when you <a href=../../concepts/fundamentals/html_js_css_files/ >define HTML, JS, or CSS as separate files</a>.</p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>COMPONENTS</span> <span class=o>=</span> <span class=n>ComponentsSettings</span><span class=p>(</span> </code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/app_settings.py#L212 target=_blank>See source code</a></p> <p>Specify the directories that contain your components.</p> <p>Defaults to <code>[Path(settings.BASE_DIR) / "components"]</code>. That is, the root <code>components/</code> app.</p> <p>Directories must be full paths, same as with <a href=https://docs.djangoproject.com/en/5.2/ref/settings/#std-setting-STATICFILES_DIRS>STATICFILES_DIRS</a>.</p> <p>These locations are searched during <a href=../../concepts/fundamentals/autodiscovery/ >autodiscovery</a>, or when you <a href=../../concepts/fundamentals/html_js_css_files/ >define HTML, JS, or CSS as separate files</a>.</p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>COMPONENTS</span> <span class=o>=</span> <span class=n>ComponentsSettings</span><span class=p>(</span>
<a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a> <span class=n>dirs</span><span class=o>=</span><span class=p>[</span><span class=n>BASE_DIR</span> <span class=o>/</span> <span class=s2>&quot;components&quot;</span><span class=p>],</span> <a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a> <span class=n>dirs</span><span class=o>=</span><span class=p>[</span><span class=n>BASE_DIR</span> <span class=o>/</span> <span class=s2>&quot;components&quot;</span><span class=p>],</span>
<a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a><span class=p>)</span> <a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a><span class=p>)</span>
</code></pre></div> <p>Set to empty list to disable global components directories:</p> <div class=highlight><pre><span></span><code><a id=__codelineno-1-1 name=__codelineno-1-1 href=#__codelineno-1-1></a><span class=n>COMPONENTS</span> <span class=o>=</span> <span class=n>ComponentsSettings</span><span class=p>(</span> </code></pre></div> <p>Set to empty list to disable global components directories:</p> <div class=highlight><pre><span></span><code><a id=__codelineno-1-1 name=__codelineno-1-1 href=#__codelineno-1-1></a><span class=n>COMPONENTS</span> <span class=o>=</span> <span class=n>ComponentsSettings</span><span class=p>(</span>
<a id=__codelineno-1-2 name=__codelineno-1-2 href=#__codelineno-1-2></a> <span class=n>dirs</span><span class=o>=</span><span class=p>[],</span> <a id=__codelineno-1-2 name=__codelineno-1-2 href=#__codelineno-1-2></a> <span class=n>dirs</span><span class=o>=</span><span class=p>[],</span>
<a id=__codelineno-1-3 name=__codelineno-1-3 href=#__codelineno-1-3></a><span class=p>)</span> <a id=__codelineno-1-3 name=__codelineno-1-3 href=#__codelineno-1-3></a><span class=p>)</span>
</code></pre></div> </div> </div> <div class="doc doc-object doc-attribute"> <h2 id=django_components.app_settings.ComponentsSettings.dynamic_component_name class="doc doc-heading"> <span class="doc doc-object-name doc-attribute-name">dynamic_component_name</span> <a href=#django_components.app_settings.ComponentsSettings.dynamic_component_name class=headerlink title="Permanent link">¤</a></h2> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>dynamic_component_name</span><span class=p>:</span> <span class=n><a class="autorefs autorefs-external" title=typing.Optional href=https://docs.python.org/3.12/library/typing.html#typing.Optional>Optional</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/stdtypes.html#str>str</a></span><span class=p>]</span> <span class=o>=</span> <span class=kc>None</span> </code></pre></div> </div> </div> <div class="doc doc-object doc-attribute"> <h2 id=django_components.app_settings.ComponentsSettings.dynamic_component_name class="doc doc-heading"> <span class="doc doc-object-name doc-attribute-name">dynamic_component_name</span> <a href=#django_components.app_settings.ComponentsSettings.dynamic_component_name class=headerlink title="Permanent link">¤</a></h2> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>dynamic_component_name</span><span class=p>:</span> <span class=n><a class="autorefs autorefs-external" title=typing.Optional href=https://docs.python.org/3.12/library/typing.html#typing.Optional>Optional</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/stdtypes.html#str>str</a></span><span class=p>]</span> <span class=o>=</span> <span class=kc>None</span>
</code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/app_settings.py#L350 target=_blank>See source code</a></p> <p>By default, the <a href=../components/#django_components.components.dynamic.DynamicComponent>dynamic component</a> is registered under the name <code>"dynamic"</code>.</p> <p>In case of a conflict, you can use this setting to change the component name used for the dynamic components.</p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=c1># settings.py</span> </code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/app_settings.py#L351 target=_blank>See source code</a></p> <p>By default, the <a href=../components/#django_components.components.dynamic.DynamicComponent>dynamic component</a> is registered under the name <code>"dynamic"</code>.</p> <p>In case of a conflict, you can use this setting to change the component name used for the dynamic components.</p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=c1># settings.py</span>
<a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a><span class=n>COMPONENTS</span> <span class=o>=</span> <span class=n>ComponentsSettings</span><span class=p>(</span> <a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a><span class=n>COMPONENTS</span> <span class=o>=</span> <span class=n>ComponentsSettings</span><span class=p>(</span>
<a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a> <span class=n>dynamic_component_name</span><span class=o>=</span><span class=s2>&quot;my_dynamic&quot;</span><span class=p>,</span> <a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a> <span class=n>dynamic_component_name</span><span class=o>=</span><span class=s2>&quot;my_dynamic&quot;</span><span class=p>,</span>
<a id=__codelineno-0-4 name=__codelineno-0-4 href=#__codelineno-0-4></a><span class=p>)</span> <a id=__codelineno-0-4 name=__codelineno-0-4 href=#__codelineno-0-4></a><span class=p>)</span>
@ -206,14 +206,14 @@
<a id=__codelineno-1-4 name=__codelineno-1-4 href=#__codelineno-1-4></a><span class=x> </span><span class=cp>{%</span> <span class=k>endfill</span> <span class=cp>%}</span> <a id=__codelineno-1-4 name=__codelineno-1-4 href=#__codelineno-1-4></a><span class=x> </span><span class=cp>{%</span> <span class=k>endfill</span> <span class=cp>%}</span>
<a id=__codelineno-1-5 name=__codelineno-1-5 href=#__codelineno-1-5></a><span class=cp>{%</span> <span class=k>endcomponent</span> <span class=cp>%}</span> <a id=__codelineno-1-5 name=__codelineno-1-5 href=#__codelineno-1-5></a><span class=cp>{%</span> <span class=k>endcomponent</span> <span class=cp>%}</span>
</code></pre></div> </div> </div> <div class="doc doc-object doc-attribute"> <h2 id=django_components.app_settings.ComponentsSettings.extensions class="doc doc-heading"> <span class="doc doc-object-name doc-attribute-name">extensions</span> <a href=#django_components.app_settings.ComponentsSettings.extensions class=headerlink title="Permanent link">¤</a></h2> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>extensions</span><span class=p>:</span> <span class=n><a class="autorefs autorefs-external" title=typing.Optional href=https://docs.python.org/3.12/library/typing.html#typing.Optional>Optional</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" title=typing.Sequence href=https://docs.python.org/3.12/library/typing.html#typing.Sequence>Sequence</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" title=typing.Union href=https://docs.python.org/3.12/library/typing.html#typing.Union>Union</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" title=typing.Type href=https://docs.python.org/3.12/library/typing.html#typing.Type>Type</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-internal" title=" ComponentExtension (django_components.extension.ComponentExtension)" href=../api/#django_components.ComponentExtension>ComponentExtension</a></span><span class=p>],</span> <span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/stdtypes.html#str>str</a></span><span class=p>]]]</span> <span class=o>=</span> <span class=kc>None</span> </code></pre></div> </div> </div> <div class="doc doc-object doc-attribute"> <h2 id=django_components.app_settings.ComponentsSettings.extensions class="doc doc-heading"> <span class="doc doc-object-name doc-attribute-name">extensions</span> <a href=#django_components.app_settings.ComponentsSettings.extensions class=headerlink title="Permanent link">¤</a></h2> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>extensions</span><span class=p>:</span> <span class=n><a class="autorefs autorefs-external" title=typing.Optional href=https://docs.python.org/3.12/library/typing.html#typing.Optional>Optional</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" title=typing.Sequence href=https://docs.python.org/3.12/library/typing.html#typing.Sequence>Sequence</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" title=typing.Union href=https://docs.python.org/3.12/library/typing.html#typing.Union>Union</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" title=typing.Type href=https://docs.python.org/3.12/library/typing.html#typing.Type>Type</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-internal" title=" ComponentExtension (django_components.extension.ComponentExtension)" href=../api/#django_components.ComponentExtension>ComponentExtension</a></span><span class=p>],</span> <span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/stdtypes.html#str>str</a></span><span class=p>]]]</span> <span class=o>=</span> <span class=kc>None</span>
</code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/app_settings.py#L152 target=_blank>See source code</a></p> <p>List of <a href=../../concepts/advanced/extensions/ >extensions</a> to be loaded.</p> <p>The extensions can be specified as:</p> <ul> <li>Python import path, e.g. <code>"path.to.my_extension.MyExtension"</code>.</li> <li>Extension class, e.g. <code>my_extension.MyExtension</code>.</li> </ul> <p>Read more about <a href=../../concepts/advanced/extensions/ >extensions</a>.</p> <p><strong>Example:</strong></p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>COMPONENTS</span> <span class=o>=</span> <span class=n>ComponentsSettings</span><span class=p>(</span> </code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/app_settings.py#L153 target=_blank>See source code</a></p> <p>List of <a href=../../concepts/advanced/extensions/ >extensions</a> to be loaded.</p> <p>The extensions can be specified as:</p> <ul> <li>Python import path, e.g. <code>"path.to.my_extension.MyExtension"</code>.</li> <li>Extension class, e.g. <code>my_extension.MyExtension</code>.</li> </ul> <p>Read more about <a href=../../concepts/advanced/extensions/ >extensions</a>.</p> <p><strong>Example:</strong></p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>COMPONENTS</span> <span class=o>=</span> <span class=n>ComponentsSettings</span><span class=p>(</span>
<a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a> <span class=n>extensions</span><span class=o>=</span><span class=p>[</span> <a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a> <span class=n>extensions</span><span class=o>=</span><span class=p>[</span>
<a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a> <span class=s2>&quot;path.to.my_extension.MyExtension&quot;</span><span class=p>,</span> <a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a> <span class=s2>&quot;path.to.my_extension.MyExtension&quot;</span><span class=p>,</span>
<a id=__codelineno-0-4 name=__codelineno-0-4 href=#__codelineno-0-4></a> <span class=n>StorybookExtension</span><span class=p>,</span> <a id=__codelineno-0-4 name=__codelineno-0-4 href=#__codelineno-0-4></a> <span class=n>StorybookExtension</span><span class=p>,</span>
<a id=__codelineno-0-5 name=__codelineno-0-5 href=#__codelineno-0-5></a> <span class=p>],</span> <a id=__codelineno-0-5 name=__codelineno-0-5 href=#__codelineno-0-5></a> <span class=p>],</span>
<a id=__codelineno-0-6 name=__codelineno-0-6 href=#__codelineno-0-6></a><span class=p>)</span> <a id=__codelineno-0-6 name=__codelineno-0-6 href=#__codelineno-0-6></a><span class=p>)</span>
</code></pre></div> </div> </div> <div class="doc doc-object doc-attribute"> <h2 id=django_components.app_settings.ComponentsSettings.extensions_defaults class="doc doc-heading"> <span class="doc doc-object-name doc-attribute-name">extensions_defaults</span> <a href=#django_components.app_settings.ComponentsSettings.extensions_defaults class=headerlink title="Permanent link">¤</a></h2> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>extensions_defaults</span><span class=p>:</span> <span class=n><a class="autorefs autorefs-external" title=typing.Optional href=https://docs.python.org/3.12/library/typing.html#typing.Optional>Optional</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" title=typing.Dict href=https://docs.python.org/3.12/library/typing.html#typing.Dict>Dict</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/stdtypes.html#str>str</a></span><span class=p>,</span> <span class=n><a class="autorefs autorefs-external" title=typing.Any href=https://docs.python.org/3.12/library/typing.html#typing.Any>Any</a></span><span class=p>]]</span> <span class=o>=</span> <span class=kc>None</span> </code></pre></div> </div> </div> <div class="doc doc-object doc-attribute"> <h2 id=django_components.app_settings.ComponentsSettings.extensions_defaults class="doc doc-heading"> <span class="doc doc-object-name doc-attribute-name">extensions_defaults</span> <a href=#django_components.app_settings.ComponentsSettings.extensions_defaults class=headerlink title="Permanent link">¤</a></h2> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>extensions_defaults</span><span class=p>:</span> <span class=n><a class="autorefs autorefs-external" title=typing.Optional href=https://docs.python.org/3.12/library/typing.html#typing.Optional>Optional</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" title=typing.Dict href=https://docs.python.org/3.12/library/typing.html#typing.Dict>Dict</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/stdtypes.html#str>str</a></span><span class=p>,</span> <span class=n><a class="autorefs autorefs-external" title=typing.Any href=https://docs.python.org/3.12/library/typing.html#typing.Any>Any</a></span><span class=p>]]</span> <span class=o>=</span> <span class=kc>None</span>
</code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/app_settings.py#L175 target=_blank>See source code</a></p> <p>Global defaults for the extension classes.</p> <p>Read more about <a href=../../concepts/advanced/extensions/#extension-defaults>Extension defaults</a>.</p> <p><strong>Example:</strong></p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>COMPONENTS</span> <span class=o>=</span> <span class=n>ComponentsSettings</span><span class=p>(</span> </code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/app_settings.py#L176 target=_blank>See source code</a></p> <p>Global defaults for the extension classes.</p> <p>Read more about <a href=../../concepts/advanced/extensions/#extension-defaults>Extension defaults</a>.</p> <p><strong>Example:</strong></p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>COMPONENTS</span> <span class=o>=</span> <span class=n>ComponentsSettings</span><span class=p>(</span>
<a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a> <span class=n>extensions_defaults</span><span class=o>=</span><span class=p>{</span> <a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a> <span class=n>extensions_defaults</span><span class=o>=</span><span class=p>{</span>
<a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a> <span class=s2>&quot;my_extension&quot;</span><span class=p>:</span> <span class=p>{</span> <a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a> <span class=s2>&quot;my_extension&quot;</span><span class=p>:</span> <span class=p>{</span>
<a id=__codelineno-0-4 name=__codelineno-0-4 href=#__codelineno-0-4></a> <span class=s2>&quot;my_setting&quot;</span><span class=p>:</span> <span class=s2>&quot;my_value&quot;</span><span class=p>,</span> <a id=__codelineno-0-4 name=__codelineno-0-4 href=#__codelineno-0-4></a> <span class=s2>&quot;my_setting&quot;</span><span class=p>:</span> <span class=s2>&quot;my_value&quot;</span><span class=p>,</span>
@ -225,8 +225,8 @@
<a id=__codelineno-0-10 name=__codelineno-0-10 href=#__codelineno-0-10></a> <span class=p>},</span> <a id=__codelineno-0-10 name=__codelineno-0-10 href=#__codelineno-0-10></a> <span class=p>},</span>
<a id=__codelineno-0-11 name=__codelineno-0-11 href=#__codelineno-0-11></a><span class=p>)</span> <a id=__codelineno-0-11 name=__codelineno-0-11 href=#__codelineno-0-11></a><span class=p>)</span>
</code></pre></div> </div> </div> <div class="doc doc-object doc-attribute"> <h2 id=django_components.app_settings.ComponentsSettings.forbidden_static_files class="doc doc-heading"> <span class="doc doc-object-name doc-attribute-name">forbidden_static_files</span> <a href=#django_components.app_settings.ComponentsSettings.forbidden_static_files class=headerlink title="Permanent link">¤</a></h2> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>forbidden_static_files</span><span class=p>:</span> <span class=n><a class="autorefs autorefs-external" title=typing.Optional href=https://docs.python.org/3.12/library/typing.html#typing.Optional>Optional</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" title=typing.List href=https://docs.python.org/3.12/library/typing.html#typing.List>List</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" title=typing.Union href=https://docs.python.org/3.12/library/typing.html#typing.Union>Union</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/stdtypes.html#str>str</a></span><span class=p>,</span> <span class=n><a class="autorefs autorefs-external" title=re.Pattern href=https://docs.python.org/3.12/library/re.html#re.Pattern>Pattern</a></span><span class=p>]]]</span> <span class=o>=</span> <span class=kc>None</span> </code></pre></div> </div> </div> <div class="doc doc-object doc-attribute"> <h2 id=django_components.app_settings.ComponentsSettings.forbidden_static_files class="doc doc-heading"> <span class="doc doc-object-name doc-attribute-name">forbidden_static_files</span> <a href=#django_components.app_settings.ComponentsSettings.forbidden_static_files class=headerlink title="Permanent link">¤</a></h2> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>forbidden_static_files</span><span class=p>:</span> <span class=n><a class="autorefs autorefs-external" title=typing.Optional href=https://docs.python.org/3.12/library/typing.html#typing.Optional>Optional</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" title=typing.List href=https://docs.python.org/3.12/library/typing.html#typing.List>List</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" title=typing.Union href=https://docs.python.org/3.12/library/typing.html#typing.Union>Union</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/stdtypes.html#str>str</a></span><span class=p>,</span> <span class=n><a class="autorefs autorefs-external" title=re.Pattern href=https://docs.python.org/3.12/library/re.html#re.Pattern>Pattern</a></span><span class=p>]]]</span> <span class=o>=</span> <span class=kc>None</span>
</code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/app_settings.py#L515 target=_blank>See source code</a></p> <p>Deprecated. Use <a href=./#django_components.app_settings.ComponentsSettings.static_files_forbidden><code>COMPONENTS.static_files_forbidden</code></a> instead.</p> </div> </div> <div class="doc doc-object doc-attribute"> <h2 id=django_components.app_settings.ComponentsSettings.libraries class="doc doc-heading"> <span class="doc doc-object-name doc-attribute-name">libraries</span> <a href=#django_components.app_settings.ComponentsSettings.libraries class=headerlink title="Permanent link">¤</a></h2> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>libraries</span><span class=p>:</span> <span class=n><a class="autorefs autorefs-external" title=typing.Optional href=https://docs.python.org/3.12/library/typing.html#typing.Optional>Optional</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" title=typing.List href=https://docs.python.org/3.12/library/typing.html#typing.List>List</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/stdtypes.html#str>str</a></span><span class=p>]]</span> <span class=o>=</span> <span class=kc>None</span> </code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/app_settings.py#L516 target=_blank>See source code</a></p> <p>Deprecated. Use <a href=./#django_components.app_settings.ComponentsSettings.static_files_forbidden><code>COMPONENTS.static_files_forbidden</code></a> instead.</p> </div> </div> <div class="doc doc-object doc-attribute"> <h2 id=django_components.app_settings.ComponentsSettings.libraries class="doc doc-heading"> <span class="doc doc-object-name doc-attribute-name">libraries</span> <a href=#django_components.app_settings.ComponentsSettings.libraries class=headerlink title="Permanent link">¤</a></h2> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>libraries</span><span class=p>:</span> <span class=n><a class="autorefs autorefs-external" title=typing.Optional href=https://docs.python.org/3.12/library/typing.html#typing.Optional>Optional</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" title=typing.List href=https://docs.python.org/3.12/library/typing.html#typing.List>List</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/stdtypes.html#str>str</a></span><span class=p>]]</span> <span class=o>=</span> <span class=kc>None</span>
</code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/app_settings.py#L376 target=_blank>See source code</a></p> <p>Configure extra python modules that should be loaded.</p> <p>This may be useful if you are not using the <a href=../../concepts/fundamentals/autodiscovery/ >autodiscovery feature</a>, or you need to load components from non-standard locations. Thus you can have a structure of components that is independent from your apps.</p> <p>Expects a list of python module paths. Defaults to empty list.</p> <p><strong>Example:</strong></p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>COMPONENTS</span> <span class=o>=</span> <span class=n>ComponentsSettings</span><span class=p>(</span> </code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/app_settings.py#L377 target=_blank>See source code</a></p> <p>Configure extra python modules that should be loaded.</p> <p>This may be useful if you are not using the <a href=../../concepts/fundamentals/autodiscovery/ >autodiscovery feature</a>, or you need to load components from non-standard locations. Thus you can have a structure of components that is independent from your apps.</p> <p>Expects a list of python module paths. Defaults to empty list.</p> <p><strong>Example:</strong></p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>COMPONENTS</span> <span class=o>=</span> <span class=n>ComponentsSettings</span><span class=p>(</span>
<a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a> <span class=n>libraries</span><span class=o>=</span><span class=p>[</span> <a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a> <span class=n>libraries</span><span class=o>=</span><span class=p>[</span>
<a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a> <span class=s2>&quot;mysite.components.forms&quot;</span><span class=p>,</span> <a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a> <span class=s2>&quot;mysite.components.forms&quot;</span><span class=p>,</span>
<a id=__codelineno-0-4 name=__codelineno-0-4 href=#__codelineno-0-4></a> <span class=s2>&quot;mysite.components.buttons&quot;</span><span class=p>,</span> <a id=__codelineno-0-4 name=__codelineno-0-4 href=#__codelineno-0-4></a> <span class=s2>&quot;mysite.components.buttons&quot;</span><span class=p>,</span>
@ -242,13 +242,13 @@
<a id=__codelineno-2-2 name=__codelineno-2-2 href=#__codelineno-2-2></a> <a id=__codelineno-2-2 name=__codelineno-2-2 href=#__codelineno-2-2></a>
<a id=__codelineno-2-3 name=__codelineno-2-3 href=#__codelineno-2-3></a><span class=n>import_libraries</span><span class=p>()</span> <a id=__codelineno-2-3 name=__codelineno-2-3 href=#__codelineno-2-3></a><span class=n>import_libraries</span><span class=p>()</span>
</code></pre></div> </div> </div> <div class="doc doc-object doc-attribute"> <h2 id=django_components.app_settings.ComponentsSettings.multiline_tags class="doc doc-heading"> <span class="doc doc-object-name doc-attribute-name">multiline_tags</span> <a href=#django_components.app_settings.ComponentsSettings.multiline_tags class=headerlink title="Permanent link">¤</a></h2> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>multiline_tags</span><span class=p>:</span> <span class=n><a class="autorefs autorefs-external" title=typing.Optional href=https://docs.python.org/3.12/library/typing.html#typing.Optional>Optional</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/functions.html#bool>bool</a></span><span class=p>]</span> <span class=o>=</span> <span class=kc>None</span> </code></pre></div> </div> </div> <div class="doc doc-object doc-attribute"> <h2 id=django_components.app_settings.ComponentsSettings.multiline_tags class="doc doc-heading"> <span class="doc doc-object-name doc-attribute-name">multiline_tags</span> <a href=#django_components.app_settings.ComponentsSettings.multiline_tags class=headerlink title="Permanent link">¤</a></h2> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>multiline_tags</span><span class=p>:</span> <span class=n><a class="autorefs autorefs-external" title=typing.Optional href=https://docs.python.org/3.12/library/typing.html#typing.Optional>Optional</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/functions.html#bool>bool</a></span><span class=p>]</span> <span class=o>=</span> <span class=kc>None</span>
</code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/app_settings.py#L421 target=_blank>See source code</a></p> <p>Enable / disable <a href=../../concepts/fundamentals/template_tag_syntax/#multiline-tags>multiline support for template tags</a>. If <code>True</code>, template tags like <code>{% component %}</code> or <code>{{ my_var }}</code> can span multiple lines.</p> <p>Defaults to <code>True</code>.</p> <p>Disable this setting if you are making custom modifications to Django's regular expression for parsing templates at <code>django.template.base.tag_re</code>.</p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>COMPONENTS</span> <span class=o>=</span> <span class=n>ComponentsSettings</span><span class=p>(</span> </code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/app_settings.py#L422 target=_blank>See source code</a></p> <p>Enable / disable <a href=../../concepts/fundamentals/template_tag_syntax/#multiline-tags>multiline support for template tags</a>. If <code>True</code>, template tags like <code>{% component %}</code> or <code>{{ my_var }}</code> can span multiple lines.</p> <p>Defaults to <code>True</code>.</p> <p>Disable this setting if you are making custom modifications to Django's regular expression for parsing templates at <code>django.template.base.tag_re</code>.</p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>COMPONENTS</span> <span class=o>=</span> <span class=n>ComponentsSettings</span><span class=p>(</span>
<a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a> <span class=n>multiline_tags</span><span class=o>=</span><span class=kc>False</span><span class=p>,</span> <a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a> <span class=n>multiline_tags</span><span class=o>=</span><span class=kc>False</span><span class=p>,</span>
<a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a><span class=p>)</span> <a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a><span class=p>)</span>
</code></pre></div> </div> </div> <div class="doc doc-object doc-attribute"> <h2 id=django_components.app_settings.ComponentsSettings.reload_on_file_change class="doc doc-heading"> <span class="doc doc-object-name doc-attribute-name">reload_on_file_change</span> <a href=#django_components.app_settings.ComponentsSettings.reload_on_file_change class=headerlink title="Permanent link">¤</a></h2> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>reload_on_file_change</span><span class=p>:</span> <span class=n><a class="autorefs autorefs-external" title=typing.Optional href=https://docs.python.org/3.12/library/typing.html#typing.Optional>Optional</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/functions.html#bool>bool</a></span><span class=p>]</span> <span class=o>=</span> <span class=kc>None</span> </code></pre></div> </div> </div> <div class="doc doc-object doc-attribute"> <h2 id=django_components.app_settings.ComponentsSettings.reload_on_file_change class="doc doc-heading"> <span class="doc doc-object-name doc-attribute-name">reload_on_file_change</span> <a href=#django_components.app_settings.ComponentsSettings.reload_on_file_change class=headerlink title="Permanent link">¤</a></h2> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>reload_on_file_change</span><span class=p>:</span> <span class=n><a class="autorefs autorefs-external" title=typing.Optional href=https://docs.python.org/3.12/library/typing.html#typing.Optional>Optional</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/functions.html#bool>bool</a></span><span class=p>]</span> <span class=o>=</span> <span class=kc>None</span>
</code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/app_settings.py#L445 target=_blank>See source code</a></p> <p>This is relevant if you are using the project structure where HTML, JS, CSS and Python are in separate files and nested in a directory.</p> <p>In this case you may notice that when you are running a development server, the server sometimes does not reload when you change component files.</p> <p>Django's native <a href=https://stackoverflow.com/a/66023029/9788634>live reload</a> logic handles only Python files and HTML template files. It does NOT reload when other file types change or when template files are nested more than one level deep.</p> <p>The setting <code>reload_on_file_change</code> fixes this, reloading the dev server even when your component's HTML, JS, or CSS changes.</p> <p>If <code>True</code>, django_components configures Django to reload when files inside <a href=./#django_components.app_settings.ComponentsSettings.dirs><code>COMPONENTS.dirs</code></a> or <a href=./#django_components.app_settings.ComponentsSettings.app_dirs><code>COMPONENTS.app_dirs</code></a> change.</p> <p>See <a href=../../guides/setup/development_server/#reload-dev-server-on-component-file-changes>Reload dev server on component file changes</a>.</p> <p>Defaults to <code>False</code>.</p> <div class="admonition warning"> <p class=admonition-title>Warning</p> <p>This setting should be enabled only for the dev environment!</p> </div> </div> </div> <div class="doc doc-object doc-attribute"> <h2 id=django_components.app_settings.ComponentsSettings.reload_on_template_change class="doc doc-heading"> <span class="doc doc-object-name doc-attribute-name">reload_on_template_change</span> <a href=#django_components.app_settings.ComponentsSettings.reload_on_template_change class=headerlink title="Permanent link">¤</a></h2> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>reload_on_template_change</span><span class=p>:</span> <span class=n><a class="autorefs autorefs-external" title=typing.Optional href=https://docs.python.org/3.12/library/typing.html#typing.Optional>Optional</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/functions.html#bool>bool</a></span><span class=p>]</span> <span class=o>=</span> <span class=kc>None</span> </code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/app_settings.py#L446 target=_blank>See source code</a></p> <p>This is relevant if you are using the project structure where HTML, JS, CSS and Python are in separate files and nested in a directory.</p> <p>In this case you may notice that when you are running a development server, the server sometimes does not reload when you change component files.</p> <p>Django's native <a href=https://stackoverflow.com/a/66023029/9788634>live reload</a> logic handles only Python files and HTML template files. It does NOT reload when other file types change or when template files are nested more than one level deep.</p> <p>The setting <code>reload_on_file_change</code> fixes this, reloading the dev server even when your component's HTML, JS, or CSS changes.</p> <p>If <code>True</code>, django_components configures Django to reload when files inside <a href=./#django_components.app_settings.ComponentsSettings.dirs><code>COMPONENTS.dirs</code></a> or <a href=./#django_components.app_settings.ComponentsSettings.app_dirs><code>COMPONENTS.app_dirs</code></a> change.</p> <p>See <a href=../../guides/setup/development_server/#reload-dev-server-on-component-file-changes>Reload dev server on component file changes</a>.</p> <p>Defaults to <code>False</code>.</p> <div class="admonition warning"> <p class=admonition-title>Warning</p> <p>This setting should be enabled only for the dev environment!</p> </div> </div> </div> <div class="doc doc-object doc-attribute"> <h2 id=django_components.app_settings.ComponentsSettings.reload_on_template_change class="doc doc-heading"> <span class="doc doc-object-name doc-attribute-name">reload_on_template_change</span> <a href=#django_components.app_settings.ComponentsSettings.reload_on_template_change class=headerlink title="Permanent link">¤</a></h2> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>reload_on_template_change</span><span class=p>:</span> <span class=n><a class="autorefs autorefs-external" title=typing.Optional href=https://docs.python.org/3.12/library/typing.html#typing.Optional>Optional</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/functions.html#bool>bool</a></span><span class=p>]</span> <span class=o>=</span> <span class=kc>None</span>
</code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/app_settings.py#L440 target=_blank>See source code</a></p> <p>Deprecated. Use <a href=./#django_components.app_settings.ComponentsSettings.reload_on_file_change><code>COMPONENTS.reload_on_file_change</code></a> instead.</p> </div> </div> <div class="doc doc-object doc-attribute"> <h2 id=django_components.app_settings.ComponentsSettings.static_files_allowed class="doc doc-heading"> <span class="doc doc-object-name doc-attribute-name">static_files_allowed</span> <a href=#django_components.app_settings.ComponentsSettings.static_files_allowed class=headerlink title="Permanent link">¤</a></h2> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>static_files_allowed</span><span class=p>:</span> <span class=n><a class="autorefs autorefs-external" title=typing.Optional href=https://docs.python.org/3.12/library/typing.html#typing.Optional>Optional</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" title=typing.List href=https://docs.python.org/3.12/library/typing.html#typing.List>List</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" title=typing.Union href=https://docs.python.org/3.12/library/typing.html#typing.Union>Union</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/stdtypes.html#str>str</a></span><span class=p>,</span> <span class=n><a class="autorefs autorefs-external" title=re.Pattern href=https://docs.python.org/3.12/library/re.html#re.Pattern>Pattern</a></span><span class=p>]]]</span> <span class=o>=</span> <span class=kc>None</span> </code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/app_settings.py#L441 target=_blank>See source code</a></p> <p>Deprecated. Use <a href=./#django_components.app_settings.ComponentsSettings.reload_on_file_change><code>COMPONENTS.reload_on_file_change</code></a> instead.</p> </div> </div> <div class="doc doc-object doc-attribute"> <h2 id=django_components.app_settings.ComponentsSettings.static_files_allowed class="doc doc-heading"> <span class="doc doc-object-name doc-attribute-name">static_files_allowed</span> <a href=#django_components.app_settings.ComponentsSettings.static_files_allowed class=headerlink title="Permanent link">¤</a></h2> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>static_files_allowed</span><span class=p>:</span> <span class=n><a class="autorefs autorefs-external" title=typing.Optional href=https://docs.python.org/3.12/library/typing.html#typing.Optional>Optional</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" title=typing.List href=https://docs.python.org/3.12/library/typing.html#typing.List>List</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" title=typing.Union href=https://docs.python.org/3.12/library/typing.html#typing.Union>Union</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/stdtypes.html#str>str</a></span><span class=p>,</span> <span class=n><a class="autorefs autorefs-external" title=re.Pattern href=https://docs.python.org/3.12/library/re.html#re.Pattern>Pattern</a></span><span class=p>]]]</span> <span class=o>=</span> <span class=kc>None</span>
</code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/app_settings.py#L475 target=_blank>See source code</a></p> <p>A list of file extensions (including the leading dot) that define which files within <a href=./#django_components.app_settings.ComponentsSettings.dirs><code>COMPONENTS.dirs</code></a> or <a href=./#django_components.app_settings.ComponentsSettings.app_dirs><code>COMPONENTS.app_dirs</code></a> are treated as <a href=https://docs.djangoproject.com/en/5.2/howto/static-files/ >static files</a>.</p> <p>If a file is matched against any of the patterns, it's considered a static file. Such files are collected when running <a href=https://docs.djangoproject.com/en/5.2/ref/contrib/staticfiles/#collectstatic><code>collectstatic</code></a>, and can be accessed under the <a href=https://docs.djangoproject.com/en/5.2/ref/settings/#static-url>static file endpoint</a>.</p> <p>You can also pass in compiled regexes (<a href=https://docs.python.org/3/library/re.html#re.Pattern><code>re.Pattern</code></a>) for more advanced patterns.</p> <p>By default, JS, CSS, and common image and font file formats are considered static files:</p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>COMPONENTS</span> <span class=o>=</span> <span class=n>ComponentsSettings</span><span class=p>(</span> </code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/app_settings.py#L476 target=_blank>See source code</a></p> <p>A list of file extensions (including the leading dot) that define which files within <a href=./#django_components.app_settings.ComponentsSettings.dirs><code>COMPONENTS.dirs</code></a> or <a href=./#django_components.app_settings.ComponentsSettings.app_dirs><code>COMPONENTS.app_dirs</code></a> are treated as <a href=https://docs.djangoproject.com/en/5.2/howto/static-files/ >static files</a>.</p> <p>If a file is matched against any of the patterns, it's considered a static file. Such files are collected when running <a href=https://docs.djangoproject.com/en/5.2/ref/contrib/staticfiles/#collectstatic><code>collectstatic</code></a>, and can be accessed under the <a href=https://docs.djangoproject.com/en/5.2/ref/settings/#static-url>static file endpoint</a>.</p> <p>You can also pass in compiled regexes (<a href=https://docs.python.org/3/library/re.html#re.Pattern><code>re.Pattern</code></a>) for more advanced patterns.</p> <p>By default, JS, CSS, and common image and font file formats are considered static files:</p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>COMPONENTS</span> <span class=o>=</span> <span class=n>ComponentsSettings</span><span class=p>(</span>
<a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a> <span class=n>static_files_allowed</span><span class=o>=</span><span class=p>[</span> <a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a> <span class=n>static_files_allowed</span><span class=o>=</span><span class=p>[</span>
<a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a> <span class=s2>&quot;.css&quot;</span><span class=p>,</span> <a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a> <span class=s2>&quot;.css&quot;</span><span class=p>,</span>
<a id=__codelineno-0-4 name=__codelineno-0-4 href=#__codelineno-0-4></a> <span class=s2>&quot;.js&quot;</span><span class=p>,</span> <span class=s2>&quot;.jsx&quot;</span><span class=p>,</span> <span class=s2>&quot;.ts&quot;</span><span class=p>,</span> <span class=s2>&quot;.tsx&quot;</span><span class=p>,</span> <a id=__codelineno-0-4 name=__codelineno-0-4 href=#__codelineno-0-4></a> <span class=s2>&quot;.js&quot;</span><span class=p>,</span> <span class=s2>&quot;.jsx&quot;</span><span class=p>,</span> <span class=s2>&quot;.ts&quot;</span><span class=p>,</span> <span class=s2>&quot;.tsx&quot;</span><span class=p>,</span>
@ -261,7 +261,7 @@
<a id=__codelineno-0-11 name=__codelineno-0-11 href=#__codelineno-0-11></a> <span class=p>],</span> <a id=__codelineno-0-11 name=__codelineno-0-11 href=#__codelineno-0-11></a> <span class=p>],</span>
<a id=__codelineno-0-12 name=__codelineno-0-12 href=#__codelineno-0-12></a><span class=p>)</span> <a id=__codelineno-0-12 name=__codelineno-0-12 href=#__codelineno-0-12></a><span class=p>)</span>
</code></pre></div> <div class="admonition warning"> <p class=admonition-title>Warning</p> <p>Exposing your Python files can be a security vulnerability. See <a href=../../overview/security_notes/ >Security notes</a>.</p> </div> </div> </div> <div class="doc doc-object doc-attribute"> <h2 id=django_components.app_settings.ComponentsSettings.static_files_forbidden class="doc doc-heading"> <span class="doc doc-object-name doc-attribute-name">static_files_forbidden</span> <a href=#django_components.app_settings.ComponentsSettings.static_files_forbidden class=headerlink title="Permanent link">¤</a></h2> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>static_files_forbidden</span><span class=p>:</span> <span class=n><a class="autorefs autorefs-external" title=typing.Optional href=https://docs.python.org/3.12/library/typing.html#typing.Optional>Optional</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" title=typing.List href=https://docs.python.org/3.12/library/typing.html#typing.List>List</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" title=typing.Union href=https://docs.python.org/3.12/library/typing.html#typing.Union>Union</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/stdtypes.html#str>str</a></span><span class=p>,</span> <span class=n><a class="autorefs autorefs-external" title=re.Pattern href=https://docs.python.org/3.12/library/re.html#re.Pattern>Pattern</a></span><span class=p>]]]</span> <span class=o>=</span> <span class=kc>None</span> </code></pre></div> <div class="admonition warning"> <p class=admonition-title>Warning</p> <p>Exposing your Python files can be a security vulnerability. See <a href=../../overview/security_notes/ >Security notes</a>.</p> </div> </div> </div> <div class="doc doc-object doc-attribute"> <h2 id=django_components.app_settings.ComponentsSettings.static_files_forbidden class="doc doc-heading"> <span class="doc doc-object-name doc-attribute-name">static_files_forbidden</span> <a href=#django_components.app_settings.ComponentsSettings.static_files_forbidden class=headerlink title="Permanent link">¤</a></h2> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>static_files_forbidden</span><span class=p>:</span> <span class=n><a class="autorefs autorefs-external" title=typing.Optional href=https://docs.python.org/3.12/library/typing.html#typing.Optional>Optional</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" title=typing.List href=https://docs.python.org/3.12/library/typing.html#typing.List>List</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" title=typing.Union href=https://docs.python.org/3.12/library/typing.html#typing.Union>Union</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/stdtypes.html#str>str</a></span><span class=p>,</span> <span class=n><a class="autorefs autorefs-external" title=re.Pattern href=https://docs.python.org/3.12/library/re.html#re.Pattern>Pattern</a></span><span class=p>]]]</span> <span class=o>=</span> <span class=kc>None</span>
</code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/app_settings.py#L520 target=_blank>See source code</a></p> <p>A list of file extensions (including the leading dot) that define which files within <a href=./#django_components.app_settings.ComponentsSettings.dirs><code>COMPONENTS.dirs</code></a> or <a href=./#django_components.app_settings.ComponentsSettings.app_dirs><code>COMPONENTS.app_dirs</code></a> will NEVER be treated as <a href=https://docs.djangoproject.com/en/5.2/howto/static-files/ >static files</a>.</p> <p>If a file is matched against any of the patterns, it will never be considered a static file, even if the file matches a pattern in <a href=./#django_components.app_settings.ComponentsSettings.static_files_allowed><code>static_files_allowed</code></a>.</p> <p>Use this setting together with <a href=./#django_components.app_settings.ComponentsSettings.static_files_allowed><code>static_files_allowed</code></a> for a fine control over what file types will be exposed.</p> <p>You can also pass in compiled regexes (<a href=https://docs.python.org/3/library/re.html#re.Pattern><code>re.Pattern</code></a>) for more advanced patterns.</p> <p>By default, any HTML and Python are considered NOT static files:</p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>COMPONENTS</span> <span class=o>=</span> <span class=n>ComponentsSettings</span><span class=p>(</span> </code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/app_settings.py#L521 target=_blank>See source code</a></p> <p>A list of file extensions (including the leading dot) that define which files within <a href=./#django_components.app_settings.ComponentsSettings.dirs><code>COMPONENTS.dirs</code></a> or <a href=./#django_components.app_settings.ComponentsSettings.app_dirs><code>COMPONENTS.app_dirs</code></a> will NEVER be treated as <a href=https://docs.djangoproject.com/en/5.2/howto/static-files/ >static files</a>.</p> <p>If a file is matched against any of the patterns, it will never be considered a static file, even if the file matches a pattern in <a href=./#django_components.app_settings.ComponentsSettings.static_files_allowed><code>static_files_allowed</code></a>.</p> <p>Use this setting together with <a href=./#django_components.app_settings.ComponentsSettings.static_files_allowed><code>static_files_allowed</code></a> for a fine control over what file types will be exposed.</p> <p>You can also pass in compiled regexes (<a href=https://docs.python.org/3/library/re.html#re.Pattern><code>re.Pattern</code></a>) for more advanced patterns.</p> <p>By default, any HTML and Python are considered NOT static files:</p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>COMPONENTS</span> <span class=o>=</span> <span class=n>ComponentsSettings</span><span class=p>(</span>
<a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a> <span class=n>static_files_forbidden</span><span class=o>=</span><span class=p>[</span> <a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a> <span class=n>static_files_forbidden</span><span class=o>=</span><span class=p>[</span>
<a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a> <span class=s2>&quot;.html&quot;</span><span class=p>,</span> <span class=s2>&quot;.django&quot;</span><span class=p>,</span> <span class=s2>&quot;.dj&quot;</span><span class=p>,</span> <span class=s2>&quot;.tpl&quot;</span><span class=p>,</span> <a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a> <span class=s2>&quot;.html&quot;</span><span class=p>,</span> <span class=s2>&quot;.django&quot;</span><span class=p>,</span> <span class=s2>&quot;.dj&quot;</span><span class=p>,</span> <span class=s2>&quot;.tpl&quot;</span><span class=p>,</span>
<a id=__codelineno-0-4 name=__codelineno-0-4 href=#__codelineno-0-4></a> <span class=c1># Python files</span> <a id=__codelineno-0-4 name=__codelineno-0-4 href=#__codelineno-0-4></a> <span class=c1># Python files</span>
@ -269,7 +269,7 @@
<a id=__codelineno-0-6 name=__codelineno-0-6 href=#__codelineno-0-6></a> <span class=p>],</span> <a id=__codelineno-0-6 name=__codelineno-0-6 href=#__codelineno-0-6></a> <span class=p>],</span>
<a id=__codelineno-0-7 name=__codelineno-0-7 href=#__codelineno-0-7></a><span class=p>)</span> <a id=__codelineno-0-7 name=__codelineno-0-7 href=#__codelineno-0-7></a><span class=p>)</span>
</code></pre></div> <div class="admonition warning"> <p class=admonition-title>Warning</p> <p>Exposing your Python files can be a security vulnerability. See <a href=../../overview/security_notes/ >Security notes</a>.</p> </div> </div> </div> <div class="doc doc-object doc-attribute"> <h2 id=django_components.app_settings.ComponentsSettings.tag_formatter class="doc doc-heading"> <span class="doc doc-object-name doc-attribute-name">tag_formatter</span> <a href=#django_components.app_settings.ComponentsSettings.tag_formatter class=headerlink title="Permanent link">¤</a></h2> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>tag_formatter</span><span class=p>:</span> <span class=n><a class="autorefs autorefs-external" title=typing.Optional href=https://docs.python.org/3.12/library/typing.html#typing.Optional>Optional</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" title=typing.Union href=https://docs.python.org/3.12/library/typing.html#typing.Union>Union</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-internal" title=" TagFormatterABC (django_components.tag_formatter.TagFormatterABC)" href=../api/#django_components.TagFormatterABC>TagFormatterABC</a></span><span class=p>,</span> <span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/stdtypes.html#str>str</a></span><span class=p>]]</span> <span class=o>=</span> <span class=kc>None</span> </code></pre></div> <div class="admonition warning"> <p class=admonition-title>Warning</p> <p>Exposing your Python files can be a security vulnerability. See <a href=../../overview/security_notes/ >Security notes</a>.</p> </div> </div> </div> <div class="doc doc-object doc-attribute"> <h2 id=django_components.app_settings.ComponentsSettings.tag_formatter class="doc doc-heading"> <span class="doc doc-object-name doc-attribute-name">tag_formatter</span> <a href=#django_components.app_settings.ComponentsSettings.tag_formatter class=headerlink title="Permanent link">¤</a></h2> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>tag_formatter</span><span class=p>:</span> <span class=n><a class="autorefs autorefs-external" title=typing.Optional href=https://docs.python.org/3.12/library/typing.html#typing.Optional>Optional</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" title=typing.Union href=https://docs.python.org/3.12/library/typing.html#typing.Union>Union</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-internal" title=" TagFormatterABC (django_components.tag_formatter.TagFormatterABC)" href=../api/#django_components.TagFormatterABC>TagFormatterABC</a></span><span class=p>,</span> <span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/stdtypes.html#str>str</a></span><span class=p>]]</span> <span class=o>=</span> <span class=kc>None</span>
</code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/app_settings.py#L557 target=_blank>See source code</a></p> <p>Configure what syntax is used inside Django templates to render components. See the <a href=../tag_formatters/ >available tag formatters</a>.</p> <p>Defaults to <code>"django_components.component_formatter"</code>.</p> <p>Learn more about <a href=../../concepts/advanced/tag_formatters/ >Customizing component tags with TagFormatter</a>.</p> <p>Can be set either as direct reference:</p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=kn>from</span><span class=w> </span><span class=nn>django_components</span><span class=w> </span><span class=kn>import</span> <span class=n>component_formatter</span> </code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/app_settings.py#L558 target=_blank>See source code</a></p> <p>Configure what syntax is used inside Django templates to render components. See the <a href=../tag_formatters/ >available tag formatters</a>.</p> <p>Defaults to <code>"django_components.component_formatter"</code>.</p> <p>Learn more about <a href=../../concepts/advanced/tag_formatters/ >Customizing component tags with TagFormatter</a>.</p> <p>Can be set either as direct reference:</p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=kn>from</span><span class=w> </span><span class=nn>django_components</span><span class=w> </span><span class=kn>import</span> <span class=n>component_formatter</span>
<a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a> <a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a>
<a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a><span class=n>COMPONENTS</span> <span class=o>=</span> <span class=n>ComponentsSettings</span><span class=p>(</span> <a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a><span class=n>COMPONENTS</span> <span class=o>=</span> <span class=n>ComponentsSettings</span><span class=p>(</span>
<a id=__codelineno-0-4 name=__codelineno-0-4 href=#__codelineno-0-4></a> <span class=s2>&quot;tag_formatter&quot;</span><span class=p>:</span> <span class=n>component_formatter</span> <a id=__codelineno-0-4 name=__codelineno-0-4 href=#__codelineno-0-4></a> <span class=s2>&quot;tag_formatter&quot;</span><span class=p>:</span> <span class=n>component_formatter</span>
@ -290,7 +290,7 @@
<a id=__codelineno-5-2 name=__codelineno-5-2 href=#__codelineno-5-2></a><span class=x> Click me!</span> <a id=__codelineno-5-2 name=__codelineno-5-2 href=#__codelineno-5-2></a><span class=x> Click me!</span>
<a id=__codelineno-5-3 name=__codelineno-5-3 href=#__codelineno-5-3></a><span class=cp>{%</span> <span class=k>endbutton</span> <span class=cp>%}</span> <a id=__codelineno-5-3 name=__codelineno-5-3 href=#__codelineno-5-3></a><span class=cp>{%</span> <span class=k>endbutton</span> <span class=cp>%}</span>
</code></pre></div> </li> </ul> </div> </div> <div class="doc doc-object doc-attribute"> <h2 id=django_components.app_settings.ComponentsSettings.template_cache_size class="doc doc-heading"> <span class="doc doc-object-name doc-attribute-name">template_cache_size</span> <a href=#django_components.app_settings.ComponentsSettings.template_cache_size class=headerlink title="Permanent link">¤</a></h2> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>template_cache_size</span><span class=p>:</span> <span class=n><a class="autorefs autorefs-external" title=typing.Optional href=https://docs.python.org/3.12/library/typing.html#typing.Optional>Optional</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/functions.html#int>int</a></span><span class=p>]</span> <span class=o>=</span> <span class=kc>None</span> </code></pre></div> </li> </ul> </div> </div> <div class="doc doc-object doc-attribute"> <h2 id=django_components.app_settings.ComponentsSettings.template_cache_size class="doc doc-heading"> <span class="doc doc-object-name doc-attribute-name">template_cache_size</span> <a href=#django_components.app_settings.ComponentsSettings.template_cache_size class=headerlink title="Permanent link">¤</a></h2> <div class="doc-signature highlight"><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>template_cache_size</span><span class=p>:</span> <span class=n><a class="autorefs autorefs-external" title=typing.Optional href=https://docs.python.org/3.12/library/typing.html#typing.Optional>Optional</a></span><span class=p>[</span><span class=n><a class="autorefs autorefs-external" href=https://docs.python.org/3.12/library/functions.html#int>int</a></span><span class=p>]</span> <span class=o>=</span> <span class=kc>None</span>
</code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/app_settings.py#L624 target=_blank>See source code</a></p> <p>DEPRECATED. Template caching will be removed in v1.</p> <p>Configure the maximum amount of Django templates to be cached.</p> <p>Defaults to <code>128</code>.</p> <p>Each time a <a href=https://docs.djangoproject.com/en/5.2/ref/templates/api/#django.template.Template>Django template</a> is rendered, it is cached to a global in-memory cache (using Python's <a href=https://docs.python.org/3/library/functools.html#functools.lru_cache><code>lru_cache</code></a> 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.</p> <p>By default the cache holds 128 component templates in memory, which should be enough for most sites. But if you have a lot of components, or if you are overriding <a href=../api/#django_components.Component.get_template><code>Component.get_template()</code></a> to render many dynamic templates, you can increase this number.</p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>COMPONENTS</span> <span class=o>=</span> <span class=n>ComponentsSettings</span><span class=p>(</span> </code></pre></div> <div class="doc doc-contents first"> <p><a href=https://github.com/django-components/django-components/tree/master/src/django_components/app_settings.py#L625 target=_blank>See source code</a></p> <p>DEPRECATED. Template caching will be removed in v1.</p> <p>Configure the maximum amount of Django templates to be cached.</p> <p>Defaults to <code>128</code>.</p> <p>Each time a <a href=https://docs.djangoproject.com/en/5.2/ref/templates/api/#django.template.Template>Django template</a> is rendered, it is cached to a global in-memory cache (using Python's <a href=https://docs.python.org/3/library/functools.html#functools.lru_cache><code>lru_cache</code></a> 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.</p> <p>By default the cache holds 128 component templates in memory, which should be enough for most sites. But if you have a lot of components, or if you are overriding <a href=../api/#django_components.Component.get_template><code>Component.get_template()</code></a> to render many dynamic templates, you can increase this number.</p> <div class=highlight><pre><span></span><code><a id=__codelineno-0-1 name=__codelineno-0-1 href=#__codelineno-0-1></a><span class=n>COMPONENTS</span> <span class=o>=</span> <span class=n>ComponentsSettings</span><span class=p>(</span>
<a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a> <span class=n>template_cache_size</span><span class=o>=</span><span class=mi>256</span><span class=p>,</span> <a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a> <span class=n>template_cache_size</span><span class=o>=</span><span class=mi>256</span><span class=p>,</span>
<a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a><span class=p>)</span> <a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a><span class=p>)</span>
</code></pre></div> <p>To remove the cache limit altogether and cache everything, set <code>template_cache_size</code> to <code>None</code>.</p> <div class=highlight><pre><span></span><code><a id=__codelineno-1-1 name=__codelineno-1-1 href=#__codelineno-1-1></a><span class=n>COMPONENTS</span> <span class=o>=</span> <span class=n>ComponentsSettings</span><span class=p>(</span> </code></pre></div> <p>To remove the cache limit altogether and cache everything, set <code>template_cache_size</code> to <code>None</code>.</p> <div class=highlight><pre><span></span><code><a id=__codelineno-1-1 name=__codelineno-1-1 href=#__codelineno-1-1></a><span class=n>COMPONENTS</span> <span class=o>=</span> <span class=n>ComponentsSettings</span><span class=p>(</span>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1,5 +1,5 @@
from pathlib import Path from pathlib import Path
from typing import List, Optional, Type from typing import Any, List, Optional, Type
import griffe import griffe
from mkdocs_util import get_mkdocstrings_plugin_handler_options, import_object, load_config from mkdocs_util import get_mkdocstrings_plugin_handler_options, import_object, load_config
@ -18,7 +18,7 @@ is_skip_docstring: bool = mkdocstrings_config.get("show_if_no_docstring", "false
class RuntimeBasesExtension(griffe.Extension): class RuntimeBasesExtension(griffe.Extension):
"""Griffe extension that lists class bases.""" """Griffe extension that lists class bases."""
def on_class_instance(self, cls: griffe.Class, **kwargs) -> None: def on_class_instance(self, cls: griffe.Class, **_kwargs: Any) -> None:
if is_skip_docstring and cls.docstring is None: if is_skip_docstring and cls.docstring is None:
return return
@ -37,7 +37,7 @@ class RuntimeBasesExtension(griffe.Extension):
class SourceCodeExtension(griffe.Extension): class SourceCodeExtension(griffe.Extension):
"""Griffe extension that adds link to the source code at the end of the docstring.""" """Griffe extension that adds link to the source code at the end of the docstring."""
def on_instance(self, obj: griffe.Object, **kwargs) -> None: def on_instance(self, obj: griffe.Object, **_kwargs: Any) -> None:
if is_skip_docstring and obj.docstring is None: if is_skip_docstring and obj.docstring is None:
return return
@ -46,7 +46,7 @@ class SourceCodeExtension(griffe.Extension):
obj.docstring.value = html + obj.docstring.value obj.docstring.value = html + obj.docstring.value
def _format_source_code_html(relative_filepath: Path, lineno: Optional[int]): def _format_source_code_html(relative_filepath: Path, lineno: Optional[int]) -> str:
# Remove trailing slash and whitespace # Remove trailing slash and whitespace
repo_url = load_config()["repo_url"].strip("/ ") repo_url = load_config()["repo_url"].strip("/ ")
branch_path = f"tree/{SOURCE_CODE_GIT_BRANCH}" branch_path = f"tree/{SOURCE_CODE_GIT_BRANCH}"

View file

@ -9,7 +9,7 @@ from mkdocs_gen_files import Nav
ROOT = pathlib.Path(__file__).parent.parent.parent ROOT = pathlib.Path(__file__).parent.parent.parent
def generate_release_notes(): def generate_release_notes() -> None:
""" """
Reads CHANGELOG.md, splits it into per-version pages, Reads CHANGELOG.md, splits it into per-version pages,
and generates an index page with links to all versions. and generates an index page with links to all versions.
@ -20,7 +20,7 @@ def generate_release_notes():
# Create the output directory if it doesn't exist # Create the output directory if it doesn't exist
(ROOT / "docs" / releases_dir).mkdir(parents=True, exist_ok=True) (ROOT / "docs" / releases_dir).mkdir(parents=True, exist_ok=True)
with open(changelog_path, "r", encoding="utf-8") as f: with changelog_path.open("r", encoding="utf-8") as f:
changelog_content = f.read() changelog_content = f.read()
# Split the changelog by version headers (e.g., "## vX.Y.Z") # Split the changelog by version headers (e.g., "## vX.Y.Z")
@ -62,7 +62,7 @@ def generate_release_notes():
# Prepare title for navigation, e.g. "v0.140.0 (2024-09-11)" # Prepare title for navigation, e.g. "v0.140.0 (2024-09-11)"
nav_title = version_title_full nav_title = version_title_full
if date_str: if date_str:
parsed_date = datetime.strptime(date_str, "%d %b %Y") parsed_date = datetime.strptime(date_str, "%d %b %Y") # noqa: DTZ007
formatted_date = parsed_date.strftime("%Y-%m-%d") formatted_date = parsed_date.strftime("%Y-%m-%d")
nav_title += f" ({formatted_date})" nav_title += f" ({formatted_date})"

View file

@ -3,22 +3,22 @@
from functools import lru_cache from functools import lru_cache
from importlib import import_module from importlib import import_module
from pathlib import Path from pathlib import Path
from typing import Dict, List, Optional, Union from typing import Any, Dict, List, Optional, Union
import griffe import griffe
import yaml # type: ignore[import-untyped] import yaml # type: ignore[import-untyped]
@lru_cache() @lru_cache
def load_config() -> Dict: def load_config() -> Dict:
mkdocs_config_str = Path("mkdocs.yml").read_text() mkdocs_config_str = Path("mkdocs.yml").read_text()
# NOTE: Use BaseLoader to avoid resolving tags like `!ENV` # NOTE: Use BaseLoader to avoid resolving tags like `!ENV`
# See https://stackoverflow.com/questions/45966633/yaml-error-could-not-determine-a-constructor-for-the-tag # See https://stackoverflow.com/questions/45966633/yaml-error-could-not-determine-a-constructor-for-the-tag
mkdocs_config = yaml.load(mkdocs_config_str, yaml.BaseLoader) mkdocs_config = yaml.load(mkdocs_config_str, yaml.BaseLoader) # noqa: S506
return mkdocs_config return mkdocs_config
@lru_cache() @lru_cache
def find_plugin(name: str) -> Optional[Dict]: def find_plugin(name: str) -> Optional[Dict]:
config = load_config() config = load_config()
plugins: List[Union[str, Dict[str, Dict]]] = config.get("plugins", []) plugins: List[Union[str, Dict[str, Dict]]] = config.get("plugins", [])
@ -27,8 +27,8 @@ def find_plugin(name: str) -> Optional[Dict]:
for plugin in plugins: for plugin in plugins:
if isinstance(plugin, str): if isinstance(plugin, str):
plugin = {plugin: {}} plugin = {plugin: {}} # noqa: PLW2901
plugin_name, plugin_conf = list(plugin.items())[0] plugin_name, plugin_conf = next(iter(plugin.items()))
if plugin_name == name: if plugin_name == name:
return plugin_conf return plugin_conf
@ -43,7 +43,7 @@ def get_mkdocstrings_plugin_handler_options() -> Optional[Dict]:
return plugin.get("handlers", {}).get("python", {}).get("options", {}) return plugin.get("handlers", {}).get("python", {}).get("options", {})
def import_object(obj: griffe.Object): def import_object(obj: griffe.Object) -> Any:
module = import_module(obj.module.path) module = import_module(obj.module.path)
runtime_obj = getattr(module, obj.name) runtime_obj = getattr(module, obj.name)
return runtime_obj return runtime_obj

View file

@ -42,19 +42,21 @@ from argparse import ArgumentParser
from importlib import import_module from importlib import import_module
from pathlib import Path from pathlib import Path
from textwrap import dedent from textwrap import dedent
from typing import Any, Dict, List, NamedTuple, Optional, Sequence, Tuple, Type, Union from typing import TYPE_CHECKING, Any, Dict, List, NamedTuple, Optional, Sequence, Tuple, Type, Union
import mkdocs_gen_files import mkdocs_gen_files
from django.conf import settings from django.conf import settings
from django.core.management.base import BaseCommand
from django.urls import URLPattern, URLResolver from django.urls import URLPattern, URLResolver
from django_components import Component, ComponentVars, ComponentCommand, TagFormatterABC from django_components import Component, ComponentCommand, ComponentVars, TagFormatterABC
from django_components.commands.components import ComponentsRootCommand from django_components.commands.components import ComponentsRootCommand
from django_components.node import BaseNode from django_components.node import BaseNode
from django_components.util.command import setup_parser_from_command from django_components.util.command import setup_parser_from_command
from django_components.util.misc import get_import_path from django_components.util.misc import get_import_path
if TYPE_CHECKING:
from django.core.management.base import BaseCommand
# NOTE: This file is an entrypoint for the `gen-files` plugin in `mkdocs.yml`. # NOTE: This file is an entrypoint for the `gen-files` plugin in `mkdocs.yml`.
# However, `gen-files` plugin runs this file as a script, NOT as a module. # However, `gen-files` plugin runs this file as a script, NOT as a module.
# That means that: # That means that:
@ -71,7 +73,7 @@ from extensions import _format_source_code_html # noqa: E402
root = Path(__file__).parent.parent.parent root = Path(__file__).parent.parent.parent
def gen_reference_api(): def gen_reference_api() -> None:
""" """
Generate documentation for the Python API of `django_components`. Generate documentation for the Python API of `django_components`.
@ -109,14 +111,14 @@ def gen_reference_api():
# options: # options:
# show_if_no_docstring: true # show_if_no_docstring: true
# ``` # ```
f.write(f"::: {module.__name__}.{name}\n" f" options:\n" f" show_if_no_docstring: true\n") f.write(f"::: {module.__name__}.{name}\n options:\n show_if_no_docstring: true\n")
f.write("\n") f.write("\n")
mkdocs_gen_files.set_edit_path(out_path, template_path) mkdocs_gen_files.set_edit_path(out_path, template_path)
def gen_reference_testing_api(): def gen_reference_testing_api() -> None:
""" """
Generate documentation for the Python API of `django_components.testing`. Generate documentation for the Python API of `django_components.testing`.
@ -142,17 +144,15 @@ def gen_reference_testing_api():
# options: # options:
# show_if_no_docstring: true # show_if_no_docstring: true
# ``` # ```
f.write(f"::: {module.__name__}.{name}\n" f" options:\n" f" show_if_no_docstring: true\n") f.write(f"::: {module.__name__}.{name}\n options:\n show_if_no_docstring: true\n")
f.write("\n") f.write("\n")
mkdocs_gen_files.set_edit_path(out_path, template_path) mkdocs_gen_files.set_edit_path(out_path, template_path)
def gen_reference_exceptions(): def gen_reference_exceptions() -> None:
""" """Generate documentation for the Exception classes included in the Python API of `django_components`."""
Generate documentation for the Exception classes included in the Python API of `django_components`.
"""
module = import_module("django_components") module = import_module("django_components")
preface = "<!-- Autogenerated by reference.py -->\n\n" preface = "<!-- Autogenerated by reference.py -->\n\n"
@ -178,14 +178,14 @@ def gen_reference_exceptions():
# options: # options:
# show_if_no_docstring: true # show_if_no_docstring: true
# ``` # ```
f.write(f"::: {module.__name__}.{name}\n" f" options:\n" f" show_if_no_docstring: true\n") f.write(f"::: {module.__name__}.{name}\n options:\n show_if_no_docstring: true\n")
f.write("\n") f.write("\n")
mkdocs_gen_files.set_edit_path(out_path, template_path) mkdocs_gen_files.set_edit_path(out_path, template_path)
def gen_reference_components(): def gen_reference_components() -> None:
""" """
Generate documentation for the Component classes (AKA pre-defined components) included Generate documentation for the Component classes (AKA pre-defined components) included
in the Python API of `django_components`. in the Python API of `django_components`.
@ -200,7 +200,7 @@ def gen_reference_components():
with mkdocs_gen_files.open(out_path, "w", encoding="utf-8") as f: with mkdocs_gen_files.open(out_path, "w", encoding="utf-8") as f:
f.write(preface + "\n\n") f.write(preface + "\n\n")
for name, obj in inspect.getmembers(module): for _name, obj in inspect.getmembers(module):
if not _is_component_cls(obj): if not _is_component_cls(obj):
continue continue
@ -236,7 +236,7 @@ def gen_reference_components():
f" show_root_heading: true\n" f" show_root_heading: true\n"
f" show_signature: false\n" f" show_signature: false\n"
f" separate_signature: false\n" f" separate_signature: false\n"
f" members: {members}\n" f" members: {members}\n",
) )
f.write("\n") f.write("\n")
@ -244,10 +244,8 @@ def gen_reference_components():
mkdocs_gen_files.set_edit_path(out_path, template_path) mkdocs_gen_files.set_edit_path(out_path, template_path)
def gen_reference_settings(): def gen_reference_settings() -> None:
""" """Generate documentation for the settings of django-components, as defined by the `ComponentsSettings` class."""
Generate documentation for the settings of django-components, as defined by the `ComponentsSettings` class.
"""
module = import_module("django_components.app_settings") module = import_module("django_components.app_settings")
preface = "<!-- Autogenerated by reference.py -->\n\n" preface = "<!-- Autogenerated by reference.py -->\n\n"
@ -293,7 +291,7 @@ def gen_reference_settings():
f" show_symbol_type_heading: false\n" f" show_symbol_type_heading: false\n"
f" show_symbol_type_toc: false\n" f" show_symbol_type_toc: false\n"
f" show_if_no_docstring: true\n" f" show_if_no_docstring: true\n"
f" show_labels: false\n" f" show_labels: false\n",
) )
f.write("\n") f.write("\n")
@ -301,7 +299,7 @@ def gen_reference_settings():
# Get attributes / methods that are unique to the subclass # Get attributes / methods that are unique to the subclass
def _get_unique_methods(base_class: Type, sub_class: Type): def _get_unique_methods(base_class: Type, sub_class: Type) -> List[str]:
base_methods = set(dir(base_class)) base_methods = set(dir(base_class))
subclass_methods = set(dir(sub_class)) subclass_methods = set(dir(sub_class))
unique_methods = subclass_methods - base_methods unique_methods = subclass_methods - base_methods
@ -332,25 +330,25 @@ def _gen_default_settings_section(app_settings_filepath: str) -> str:
# #
# However, for the documentation, we need to remove those. # However, for the documentation, we need to remove those.
dynamic_re = re.compile(r"Dynamic\(lambda\: (?P<code>.+)\)") dynamic_re = re.compile(r"Dynamic\(lambda\: (?P<code>.+)\)")
cleaned_snippet_lines = [] cleaned_snippet_lines: List[str] = []
for line in defaults_snippet_lines: for line in defaults_snippet_lines:
line = comment_re.split(line)[0].rstrip() curr_line = comment_re.split(line)[0].rstrip()
line = dynamic_re.sub( curr_line = dynamic_re.sub(
lambda m: m.group("code"), lambda m: m.group("code"),
line, curr_line,
) )
cleaned_snippet_lines.append(line) cleaned_snippet_lines.append(curr_line)
clean_defaults_snippet = "\n".join(cleaned_snippet_lines) clean_defaults_snippet = "\n".join(cleaned_snippet_lines)
return ( return (
"### Settings defaults\n\n" "### Settings defaults\n\n"
"Here's overview of all available settings and their defaults:\n\n" "Here's overview of all available settings and their defaults:\n\n"
+ f"```py\n{clean_defaults_snippet}\n```" f"```py\n{clean_defaults_snippet}\n```"
+ "\n\n" "\n\n"
) )
def gen_reference_tagformatters(): def gen_reference_tagformatters() -> None:
""" """
Generate documentation for all pre-defined TagFormatters included Generate documentation for all pre-defined TagFormatters included
in the Python API of `django_components`. in the Python API of `django_components`.
@ -387,7 +385,7 @@ def gen_reference_tagformatters():
formatted_instances = "\n".join(formatted_instances_lines) formatted_instances = "\n".join(formatted_instances_lines)
f.write("### Available tag formatters\n\n" + formatted_instances) f.write("### Available tag formatters\n\n" + formatted_instances)
for name, obj in tag_formatter_classes.items(): for obj in tag_formatter_classes.values():
class_name = get_import_path(obj) class_name = get_import_path(obj)
# Generate reference entry for each TagFormatter class. # Generate reference entry for each TagFormatter class.
@ -408,7 +406,7 @@ def gen_reference_tagformatters():
f" show_symbol_type_toc: false\n" f" show_symbol_type_toc: false\n"
f" show_if_no_docstring: true\n" f" show_if_no_docstring: true\n"
f" show_labels: false\n" f" show_labels: false\n"
f" members: false\n" f" members: false\n",
) )
f.write("\n") f.write("\n")
@ -416,10 +414,8 @@ def gen_reference_tagformatters():
mkdocs_gen_files.set_edit_path(out_path, template_path) mkdocs_gen_files.set_edit_path(out_path, template_path)
def gen_reference_urls(): def gen_reference_urls() -> None:
""" """Generate documentation for all URLs (`urlpattern` entries) defined by django-components."""
Generate documentation for all URLs (`urlpattern` entries) defined by django-components.
"""
module = import_module("django_components.urls") module = import_module("django_components.urls")
preface = "<!-- Autogenerated by reference.py -->\n\n" preface = "<!-- Autogenerated by reference.py -->\n\n"
@ -437,7 +433,7 @@ def gen_reference_urls():
f.write("\n".join([f"- `{url_path}`\n" for url_path in all_urls])) f.write("\n".join([f"- `{url_path}`\n" for url_path in all_urls]))
def gen_reference_commands(): def gen_reference_commands() -> None:
""" """
Generate documentation for all Django admin commands defined by django-components. Generate documentation for all Django admin commands defined by django-components.
@ -474,7 +470,7 @@ def gen_reference_commands():
# becomes this: # becomes this:
# `usage: python manage.py components ext run [-h]` # `usage: python manage.py components ext run [-h]`
cmd_usage = cmd_usage[:7] + "python manage.py " + " ".join(cmd_path) + " " + cmd_usage[7:] cmd_usage = cmd_usage[:7] + "python manage.py " + " ".join(cmd_path) + " " + cmd_usage[7:]
formatted_args = _format_command_args(cmd_parser, cmd_path + (cmd_def_cls.name,)) formatted_args = _format_command_args(cmd_parser, (*cmd_path, cmd_def_cls.name))
# Add link to source code # Add link to source code
module_abs_path = import_module(cmd_def_cls.__module__).__file__ module_abs_path = import_module(cmd_def_cls.__module__).__file__
@ -483,7 +479,7 @@ def gen_reference_commands():
# NOTE: Raises `OSError` if the file is not found. # NOTE: Raises `OSError` if the file is not found.
try: try:
obj_lineno = inspect.findsource(cmd_def_cls)[1] obj_lineno = inspect.findsource(cmd_def_cls)[1]
except Exception: except Exception: # noqa: BLE001
obj_lineno = None obj_lineno = None
source_code_link = _format_source_code_html(module_rel_path, obj_lineno) source_code_link = _format_source_code_html(module_rel_path, obj_lineno)
@ -498,12 +494,12 @@ def gen_reference_commands():
f"{source_code_link}\n\n" f"{source_code_link}\n\n"
f"{cmd_summary}\n\n" f"{cmd_summary}\n\n"
f"{formatted_args}\n\n" f"{formatted_args}\n\n"
f"{cmd_desc}\n\n" f"{cmd_desc}\n\n",
) )
# Add subcommands # Add subcommands
for subcmd_cls in reversed(cmd_def_cls.subcommands): for subcmd_cls in reversed(cmd_def_cls.subcommands):
commands_stack.append((subcmd_cls, cmd_path + (cmd_def_cls.name,))) commands_stack.append((subcmd_cls, (*cmd_path, cmd_def_cls.name)))
# TODO_v1 - REMOVE - This this section as it only for legacy commands `startcomponent` and `upgradecomponent` # TODO_v1 - REMOVE - This this section as it only for legacy commands `startcomponent` and `upgradecomponent`
command_files = Path("./src/django_components/management/commands").glob("*.py") command_files = Path("./src/django_components/management/commands").glob("*.py")
@ -540,13 +536,13 @@ def gen_reference_commands():
f"{source_code_link}\n\n" f"{source_code_link}\n\n"
f"{cmd_summary}\n\n" f"{cmd_summary}\n\n"
f"{formatted_args}\n\n" f"{formatted_args}\n\n"
f"{cmd_desc}\n\n" f"{cmd_desc}\n\n",
) )
mkdocs_gen_files.set_edit_path(out_path, template_path) mkdocs_gen_files.set_edit_path(out_path, template_path)
def gen_reference_template_tags(): def gen_reference_template_tags() -> None:
""" """
Generate documentation for all Django template tags defined by django-components, Generate documentation for all Django template tags defined by django-components,
like `{% slot %}`, `{% component %}`, etc. like `{% slot %}`, `{% component %}`, etc.
@ -573,7 +569,7 @@ def gen_reference_template_tags():
f.write( f.write(
f"All following template tags are defined in\n\n" f"All following template tags are defined in\n\n"
f"`{mod_path}`\n\n" f"`{mod_path}`\n\n"
f"Import as\n```django\n{{% load {mod_name} %}}\n```\n\n" f"Import as\n```django\n{{% load {mod_name} %}}\n```\n\n",
) )
for _, obj in inspect.getmembers(tags_module): for _, obj in inspect.getmembers(tags_module):
@ -597,19 +593,21 @@ def gen_reference_template_tags():
# {% component [arg, ...] **kwargs [only] %} # {% component [arg, ...] **kwargs [only] %}
# {% endcomponent %} # {% endcomponent %}
# ``` # ```
# fmt: off
f.write( f.write(
f"## {name}\n\n" f"## {name}\n\n"
f"```django\n" f"```django\n"
f"{tag_signature}\n" f"{tag_signature}\n"
f"```\n\n" f"```\n\n"
f"{source_code_link}\n\n" f"{source_code_link}\n\n"
f"{docstring}\n\n" f"{docstring}\n\n",
) )
# fmt: on
mkdocs_gen_files.set_edit_path(out_path, template_path) mkdocs_gen_files.set_edit_path(out_path, template_path)
def gen_reference_template_variables(): def gen_reference_template_variables() -> None:
""" """
Generate documentation for all variables that are available inside the component templates Generate documentation for all variables that are available inside the component templates
under the `{{ component_vars }}` variable, as defined by `ComponentVars`. under the `{{ component_vars }}` variable, as defined by `ComponentVars`.
@ -628,10 +626,8 @@ def gen_reference_template_variables():
mkdocs_gen_files.set_edit_path(out_path, template_path) mkdocs_gen_files.set_edit_path(out_path, template_path)
def gen_reference_extension_hooks(): def gen_reference_extension_hooks() -> None:
""" """Generate documentation for the hooks that are available to the extensions."""
Generate documentation for the hooks that are available to the extensions.
"""
module = import_module("django_components.extension") module = import_module("django_components.extension")
preface = "<!-- Autogenerated by reference.py -->\n\n" preface = "<!-- Autogenerated by reference.py -->\n\n"
@ -691,7 +687,7 @@ def gen_reference_extension_hooks():
f" show_symbol_type_heading: false\n" f" show_symbol_type_heading: false\n"
f" show_symbol_type_toc: false\n" f" show_symbol_type_toc: false\n"
f" show_if_no_docstring: true\n" f" show_if_no_docstring: true\n"
f" show_labels: false\n" f" show_labels: false\n",
) )
f.write("\n") f.write("\n")
f.write(available_data) f.write(available_data)
@ -714,7 +710,7 @@ def gen_reference_extension_hooks():
f"::: {module.__name__}.{name}\n" f"::: {module.__name__}.{name}\n"
f" options:\n" f" options:\n"
f" heading_level: 3\n" f" heading_level: 3\n"
f" show_if_no_docstring: true\n" f" show_if_no_docstring: true\n",
) )
f.write("\n") f.write("\n")
@ -722,10 +718,8 @@ def gen_reference_extension_hooks():
mkdocs_gen_files.set_edit_path(out_path, template_path) mkdocs_gen_files.set_edit_path(out_path, template_path)
def gen_reference_extension_commands(): def gen_reference_extension_commands() -> None:
""" """Generate documentation for the objects related to defining extension commands."""
Generate documentation for the objects related to defining extension commands.
"""
module = import_module("django_components") module = import_module("django_components")
preface = "<!-- Autogenerated by reference.py -->\n\n" preface = "<!-- Autogenerated by reference.py -->\n\n"
@ -753,7 +747,7 @@ def gen_reference_extension_commands():
f"::: {module.__name__}.{name}\n" f"::: {module.__name__}.{name}\n"
f" options:\n" f" options:\n"
f" heading_level: 3\n" f" heading_level: 3\n"
f" show_if_no_docstring: true\n" f" show_if_no_docstring: true\n",
) )
f.write("\n") f.write("\n")
@ -761,10 +755,8 @@ def gen_reference_extension_commands():
mkdocs_gen_files.set_edit_path(out_path, template_path) mkdocs_gen_files.set_edit_path(out_path, template_path)
def gen_reference_extension_urls(): def gen_reference_extension_urls() -> None:
""" """Generate documentation for the objects related to defining extension URLs."""
Generate documentation for the objects related to defining extension URLs.
"""
module = import_module("django_components") module = import_module("django_components")
preface = "<!-- Autogenerated by reference.py -->\n\n" preface = "<!-- Autogenerated by reference.py -->\n\n"
@ -792,7 +784,7 @@ def gen_reference_extension_urls():
f"::: {module.__name__}.{name}\n" f"::: {module.__name__}.{name}\n"
f" options:\n" f" options:\n"
f" heading_level: 3\n" f" heading_level: 3\n"
f" show_if_no_docstring: true\n" f" show_if_no_docstring: true\n",
) )
f.write("\n") f.write("\n")
@ -855,7 +847,7 @@ def _extract_property_docstrings(cls: Type) -> Dict[str, str]:
and that the body is indented with 4 spaces. and that the body is indented with 4 spaces.
""" """
lines, start_line_index = inspect.getsourcelines(cls) lines, start_line_index = inspect.getsourcelines(cls)
attrs_lines = [] attrs_lines: List[str] = []
ignore = True ignore = True
for line in lines: for line in lines:
if ignore: if ignore:
@ -863,10 +855,9 @@ def _extract_property_docstrings(cls: Type) -> Dict[str, str]:
ignore = False ignore = False
continue continue
# Ignore comments # Ignore comments
elif line.strip().startswith("#"): if line.strip().startswith("#"):
continue continue
else: attrs_lines.append(line)
attrs_lines.append(line)
attrs_docstrings = {} attrs_docstrings = {}
curr_attr = None curr_attr = None
@ -886,7 +877,7 @@ def _extract_property_docstrings(cls: Type) -> Dict[str, str]:
attrs_docstrings[curr_attr] = "" attrs_docstrings[curr_attr] = ""
state = "before_attr_docstring" state = "before_attr_docstring"
elif state == "before_attr_docstring": elif state == "before_attr_docstring":
if not is_one_indent or not (line.startswith("'''") or line.startswith('"""')): if not is_one_indent or not line.startswith(("'''", '"""')):
continue continue
# Found start of docstring # Found start of docstring
docstring_delimiter = line[0:3] docstring_delimiter = line[0:3]
@ -909,7 +900,7 @@ def _extract_property_docstrings(cls: Type) -> Dict[str, str]:
# NOTE: Unlike other references, the API of Signals is not yet codified (AKA source of truth defined # NOTE: Unlike other references, the API of Signals is not yet codified (AKA source of truth defined
# as Python code). Instead, we manually list all signals that are sent by django-components. # as Python code). Instead, we manually list all signals that are sent by django-components.
def gen_reference_signals(): def gen_reference_signals() -> None:
""" """
Generate documentation for all [Django Signals](https://docs.djangoproject.com/en/5.2/ref/signals) that are Generate documentation for all [Django Signals](https://docs.djangoproject.com/en/5.2/ref/signals) that are
send by or during the use of django-components. send by or during the use of django-components.
@ -925,7 +916,7 @@ def gen_reference_signals():
mkdocs_gen_files.set_edit_path(out_path, template_path) mkdocs_gen_files.set_edit_path(out_path, template_path)
def _list_urls(urlpatterns: Sequence[Union[URLPattern, URLResolver]], prefix=""): def _list_urls(urlpatterns: Sequence[Union[URLPattern, URLResolver]], prefix: str = "") -> List[str]:
"""Recursively extract all URLs and their associated views from Django's urlpatterns""" """Recursively extract all URLs and their associated views from Django's urlpatterns"""
urls: List[str] = [] urls: List[str] = []
@ -1077,7 +1068,7 @@ def _parse_command_args(cmd_inputs: str) -> Dict[str, List[Dict]]:
return data return data
def _format_command_args(cmd_parser: ArgumentParser, cmd_path: Optional[Sequence[str]] = None): def _format_command_args(cmd_parser: ArgumentParser, cmd_path: Optional[Sequence[str]] = None) -> str:
cmd_inputs: str = _gen_command_args(cmd_parser) cmd_inputs: str = _gen_command_args(cmd_parser)
parsed_cmd_inputs = _parse_command_args(cmd_inputs) parsed_cmd_inputs = _parse_command_args(cmd_inputs)
@ -1131,9 +1122,8 @@ def _is_extension_url_api(obj: Any) -> bool:
return inspect.isclass(obj) and getattr(obj, "_extension_url_api", False) return inspect.isclass(obj) and getattr(obj, "_extension_url_api", False)
def gen_reference(): def gen_reference() -> None:
"""The entrypoint to generate all the reference documentation.""" """The entrypoint to generate all the reference documentation."""
# Set up Django settings so we can import `extensions` # Set up Django settings so we can import `extensions`
if not settings.configured: if not settings.configured:
settings.configure( settings.configure(

File diff suppressed because one or more lines are too long

View file

@ -1,7 +1,7 @@
[ [
{ {
"version": "dev", "version": "dev",
"title": "dev (b557ca5)", "title": "dev (f100cc1)",
"aliases": [] "aliases": []
}, },
{ {