mirror of
https://github.com/django-components/django-components.git
synced 2025-09-18 19:59:46 +00:00

Some checks are pending
Docs - build & deploy / docs (push) Waiting to run
Run tests / build (ubuntu-latest, 3.10) (push) Waiting to run
Run tests / build (ubuntu-latest, 3.11) (push) Waiting to run
Run tests / build (ubuntu-latest, 3.12) (push) Waiting to run
Run tests / build (ubuntu-latest, 3.13) (push) Waiting to run
Run tests / build (ubuntu-latest, 3.8) (push) Waiting to run
Run tests / test_sampleproject (3.13) (push) Waiting to run
Run tests / build (ubuntu-latest, 3.9) (push) Waiting to run
Run tests / build (windows-latest, 3.10) (push) Waiting to run
Run tests / build (windows-latest, 3.11) (push) Waiting to run
Run tests / build (windows-latest, 3.12) (push) Waiting to run
Run tests / build (windows-latest, 3.13) (push) Waiting to run
Run tests / build (windows-latest, 3.8) (push) Waiting to run
Run tests / build (windows-latest, 3.9) (push) Waiting to run
Run tests / test_docs (3.13) (push) Waiting to run
39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
from django.http import HttpRequest, HttpResponse
|
|
|
|
from django_components import Component, register, types
|
|
|
|
|
|
@register("greeting")
|
|
class Greeting(Component):
|
|
template: types.django_html = """
|
|
<div id="greeting">Hello, {{ name }}!</div>
|
|
{% slot "message" %}{% endslot %}
|
|
"""
|
|
|
|
css: types.css = """
|
|
#greeting {
|
|
display: inline-block;
|
|
color: blue;
|
|
font-size: 2em;
|
|
}
|
|
"""
|
|
|
|
js: types.js = """
|
|
document.getElementById("greeting").addEventListener("click", (event) => {
|
|
alert("Hello!");
|
|
});
|
|
"""
|
|
|
|
def get_template_data(self, args, kwargs, slots, context):
|
|
return {"name": kwargs["name"]}
|
|
|
|
class View:
|
|
def get(self, request: HttpRequest, *args, **kwargs) -> HttpResponse:
|
|
slots = {"message": "Hello, world!"}
|
|
return Greeting.render_to_response(
|
|
request=request,
|
|
slots=slots,
|
|
kwargs={
|
|
"name": request.GET.get("name", ""),
|
|
},
|
|
)
|