I’ll try to give context at the best of my possibility
WidgetApp/widgets.py
class WidgetApp(forms.Textarea):
template_name = 'template_textarea.html'
def __init__(self, attrs=None):
user = '************'
pass = '************'
default_attrs = {'cols': '80',
'rows': '20',
'servicelink': '**********************************',
'jsBaseUrl': '/static/WidgetApp/js',
'cssBaseUrl': '/static/WidgetApp/css',
'soundsBaseUrl': '/static/WidgetApp/sounds',
'user': user,
'pass':pass,
}
if attrs:
default_attrs.update(attrs)
super().__init__(default_attrs)
class Media:
css = {
"all": ["WidgetApp/folder1/css1.css",
"WidgetApp/folder2/folder/css2.min.css",
]
}
js = [
"WidgetApp/folder1/first.js",
#other scripts here
"WidgetApp/folder2/last.js",
"WidgetApp/js/script.js",
]
WidgetApp/templates/template_textarea.html
<div class="WidgetApp_container" id="{{ widget.attrs.id }}_div">
<textarea name="{{ widget.name }}"{% include "django/forms/widgets/attrs.html" %}>
{% if widget.value %}{{ widget.value }}{% endif %}
</textarea>
</div>
WidgetApp/forms.py
from django import forms
from .widgets import WidgetApp
class TestForm(forms.Form):
text_html = forms.CharField(label='', widget=WidgetApp())
WidgetApp/views.py
from django.http import HttpResponseRedirect
from django.shortcuts import render
from .forms import TestForm
def TestFormView(request):
if request.method == "POST":
form = TestForm(request.POST)
if form.is_valid():
return HttpResponseRedirect("/thanks/")
else:
form = TestForm()
return render(request, "template.html", {"form": form})
WidgetApp/templates/template.html
<!DOCTYPE html>
<html>
<head>
{{ form.media }}
</head>
<body>
<form action="">
{{ form }}
</form>
</body>
</html>
This above is the WidgetApp where my test url works properly and loads everything as intended.
Mainapp/forms.py
from WidgetApp.widgets import WidgetApp
class ActualForm(forms.ModelForm):
text_html = forms.CharField(widget=WidgetApp())
Mainapp/views.py
class View():
model = models.ActualForm
success_url = reverse_lazy('factualform_list')
permission_required = ['change_actualform']
form_class = forms.ActualForm
Form template is complex but the contains the elements
{% load static %}
{{ form.media }}
<!-- -->
<div id="mcewrapper" class="flex-wrapper flex-vfill{% if form.text_html.errors %} has-error{% endif %}">
{{ form.text_html|safe }}
</div>
Hope this helps to clarify the situation. As told before it seems that the widget loading in the Mainapp/forms.py doesn’t load the WidgetApp static files.