Fix issue #368 and add tests (#369)

This commit is contained in:
Dylan Castillo 2024-01-27 23:10:03 +01:00 committed by GitHub
parent 997ed52bb6
commit dc9f1b46b2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 106 additions and 9 deletions

View file

@ -0,0 +1,26 @@
from typing import Any, Dict
from django.http import HttpResponse
from django_components import component
@component.register("single_file_component")
class SingleFileComponent(component.Component):
template = """
<form method="post">
{% csrf_token %}
<input type="text" name="variable" value="{{ variable }}">
<input type="submit">
</form>
"""
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}