mirror of
https://github.com/django-components/django-components.git
synced 2025-08-31 11:17:21 +00:00
Render components as views (#366) (thanks @dylanjcastillo)
This commit is contained in:
parent
b29e7fba80
commit
91b4accfeb
10 changed files with 347 additions and 15 deletions
|
@ -1,13 +1,21 @@
|
|||
from typing import Any, Dict
|
||||
|
||||
from django_components import component
|
||||
|
||||
|
||||
@component.register("greeting")
|
||||
class greeting(component.Component):
|
||||
def get_context_data(self, greet, *args, **kwargs):
|
||||
return {"greet": greet}
|
||||
class Greeting(component.Component):
|
||||
def get(self, request, *args, **kwargs):
|
||||
slots = {"message": "Hello, world!"}
|
||||
context = {"name": request.GET.get("name", "")}
|
||||
return self.render_to_response(context, slots)
|
||||
|
||||
def get_context_data(self, name, *args, **kwargs) -> Dict[str, Any]:
|
||||
return {"name": name}
|
||||
|
||||
template = """
|
||||
<div id="greeting">{{ greet }}</div>
|
||||
<div id="greeting">Hello, {{ name }}!</div>
|
||||
{% slot "message" %}{% endslot %}
|
||||
"""
|
||||
|
||||
css = """
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue