Prompt Editor

Template editing with {{variable}} highlighting.

python 7 params

Preview

{{topic}} = djust LiveView{{audience}} = a Django developer
Summarise djust LiveView for a Django developer in three bullet points.
Arguments
prompt_editor(template='Summarise {{topic}} for {{audience}} in three bullet points.', variables={'topic': 'djust LiveView', 'audience': 'a Django developer'})

Usage

views.py
python
from djust import LiveView
from djust.decorators import event_handler
from djust.components import PromptEditor


class MyView(LiveView):
    template_name = "my_template.html"

    def mount(self, request, **kwargs):
        self.component = PromptEditor(template='Summarise {{topic}} for {{audience}} in three bullet points.', variables={'topic': 'djust LiveView', 'audience': 'a Django developer'})

    @event_handler()
    def save_prompt(self, value=None, **kwargs):
        ...  # write to self.component; the re-render carries it
my_template.html
django
{{ component }}

Events this component sends to the view: save_prompt.

Parameters

NameTypeDefault
templatestr''
variablesDict[str, str] | NoneNone
eventstr — renames the event; identity is `name`'save_prompt'
placeholderstr'Enter your prompt template...'
rowsint6
custom_classstr''
**kwargs— passed to `Component.__init__`: `name=` identifies the instance in the events it sends, `id=` sets `component.id`, and any other keyword is kept as state
Source & styles
FilePathNotes
moduledjust.components.components.prompt_editorSubclass it, or pass custom_class, to change how it renders.
cssdjust_components/components.cssDefines 7 of this component's classes at line 2280, 2281, 2282, 2283, 2284, 2285, 2286. Override those rules, or the custom properties they read, in a stylesheet loaded after it.