Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
erwinfeser opened this issue Aug 11, 2022 · 1 comment

Comments

@erwinfeser
Copy link

erwinfeser commented Aug 11, 2022

  • 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>
@kc2684
Copy link

kc2684 commented Sep 11, 2022

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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants