jmrivas86/django-json-widget

Exception while resolving variable 'style' in template 'django_json_widget.html'.

Opened this issue · 1 comments

  • django-json-widget version: 1.1.1
  • Django version: 4.0.6
  • Python version: 3.10.5
  • Operating System: Debian

Description

It works but I get an ugly log (DEBUG=True) message because django_json_widget.html template asks {% if not widget.attrs.style %} but style does not exist in attrs.

I defined my form like this:

class MyModelForm(forms.ModelForm):
    class Meta:
        model = MyModel
        fields = (
            "name",
            "config",
        )
        widgets = {
            "config": JSONEditorWidget(width="600px"),
        }

My recommendation is to replace in that template:

<div {% if not widget.attrs.style %}style="height:{{widget.height|default:'500px'}};width:{{widget.width|default:'90%'}};display:inline-block;"{% endif %}{% include "django/forms/widgets/attrs.html" %}></div>

by

<div style="height:{{widget.height|default:'500px'}};width:{{widget.width|default:'90%'}};display:inline-block;"></div>

I had the same issue. I resolved it by creating a fork at https://github.com/kc2684/django-json-widget and adding a "style" variable to "widgets.py" and then use "widget.style" in django_json_widget.html instead of "widget.attr.style"