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'})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 itmy_template.html
django
{{ component }}Events this component sends to the view: save_prompt.
Parameters
| Name | Type | Default |
|---|---|---|
| template | str | '' |
| variables | Dict[str, str] | None | None |
| event | str — renames the event; identity is `name` | 'save_prompt' |
| placeholder | str | 'Enter your prompt template...' |
| rows | int | 6 |
| custom_class | str | '' |
| **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 2280, 2281, 2282, 2283, 2284, 2285, 2286. Override those rules, or the custom properties they read, in a stylesheet loaded after it. |