mirror of
https://github.com/django-components/django-components.git
synced 2025-09-26 15:39:08 +00:00
Resolve media and template files relative to component class dir (#395), thanks @JuroOravec
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Emil Stenström <emil@emilstenstrom.se>
This commit is contained in:
parent
1de859bd34
commit
37fd901908
21 changed files with 477 additions and 43 deletions
3
tests/components/relative_file/relative_file.css
Normal file
3
tests/components/relative_file/relative_file.css
Normal file
|
@ -0,0 +1,3 @@
|
|||
.html-css-only {
|
||||
color: blue;
|
||||
}
|
5
tests/components/relative_file/relative_file.html
Normal file
5
tests/components/relative_file/relative_file.html
Normal file
|
@ -0,0 +1,5 @@
|
|||
<form method="post">
|
||||
{% csrf_token %}
|
||||
<input type="text" name="variable" value="{{ variable }}">
|
||||
<input type="submit">
|
||||
</form>
|
1
tests/components/relative_file/relative_file.js
Normal file
1
tests/components/relative_file/relative_file.js
Normal file
|
@ -0,0 +1 @@
|
|||
console.log("JS file");
|
24
tests/components/relative_file/relative_file.py
Normal file
24
tests/components/relative_file/relative_file.py
Normal file
|
@ -0,0 +1,24 @@
|
|||
from typing import Any, Dict
|
||||
|
||||
from django.http import HttpResponse
|
||||
|
||||
from django_components import component
|
||||
|
||||
|
||||
@component.register("relative_file_component")
|
||||
class RelativeFileComponent(component.Component):
|
||||
template_name = "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}
|
Loading…
Add table
Add a link
Reference in a new issue