django-components/tests/components/relative_file/relative_file.py
Juro Oravec d94a459c8d
refactor: rename template_name to template_file (#878)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-01-01 17:06:14 +01:00

24 lines
734 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"
def post(self, request, *args, **kwargs) -> HttpResponse:
variable = request.POST.get("variable")
return self.render_to_response({"variable": variable})
def get(self, request, *args, **kwargs) -> HttpResponse:
return self.render_to_response({"variable": "GET"})
def get_context_data(self, variable, *args, **kwargs) -> Dict[str, Any]:
return {"variable": variable}