django-components/tests/components/relative_file/relative_file.py
Juro Oravec 28b61c1609
refactor: Update docs and tests to use get_template_data() (#1161)
* refactor: update docs and tests to use get_template_data()

* refactor: fix linting

* docs: add note about difference between the two methods
2025-05-03 12:04:10 +02:00

31 lines
960 B
Python

from typing import Any, Dict
from django.http import HttpResponse
from django_components import Component, register
@register("relative_file_component")
class RelativeFileComponent(Component):
template_file = "relative_file.html"
class Media:
js = "relative_file.js"
css = "relative_file.css"
class View:
def post(self, request, *args, **kwargs) -> HttpResponse:
variable = request.POST.get("variable")
return RelativeFileComponent.render_to_response(
request=request,
kwargs={"variable": variable},
)
def get(self, request, *args, **kwargs) -> HttpResponse:
return RelativeFileComponent.render_to_response(
request=request,
kwargs={"variable": "GET"},
)
def get_template_data(self, args, kwargs, slots, context) -> Dict[str, Any]:
return {"variable": kwargs["variable"]}