Prompt Editor
Template editing with {{variable}} highlighting.
Preview
{{topic}} = djust LiveView{{audience}} = a Django developerSummarise 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'})This composed editor receives its state from the host view, so it has no standalone preview.
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):
pass # your app acts on 'save_prompt'; no component state movesmy_template.html
django
{{ component }}Events this component sends to the view: save_prompt.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| template | str | '' | The template string with {{variable}} placeholders. |
| variables | Dict[str, str] | None | None | Dict of variable name -> value for preview. |
| event | str — renames the event; identity is `name` | 'save_prompt' | Event name for save action. |
| placeholder | str | 'Enter your prompt template...' | Placeholder text for the editor. |
| rows | int | 6 | Number of rows for the textarea. |
| custom_class | str | '' | Additional CSS classes. |
| **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
| File | Path | Notes |
|---|---|---|
| module | djust.components.components.prompt_editor | Subclass it, or pass custom_class, to change how it renders. |
| css | djust_components/components.css | Defines 7 of this component's classes at line 2356, 2357, 2358, 2359, 2360, 2361, 2362. Override those rules, or the custom properties they read, in a stylesheet loaded after it. |