jmrivas86 / django-json-widget

An alternative widget that makes it easy to edit the new Django's field JSONField (PostgreSQL specific model fields)
MIT License
440 stars 88 forks source link

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

Open erwinfeser opened 2 years ago

erwinfeser commented 2 years ago

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>
kc2684 commented 2 years ago

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"