tzangms / django-bootstrap-form

Twitter Bootstrap for Django Form
BSD 3-Clause "New" or "Revised" License
557 stars 183 forks source link

Exception while resolving variable 'required_css_class' in template 'bootstrapform/form.html'. #92

Open montaro opened 7 years ago

montaro commented 7 years ago

I always see this error in logs, I use:

django-bootstrap-form==3.2.1 
pinax-theme-bootstrap==7.11.0
rowanv commented 7 years ago

Am experiencing this as well, also using django-bootstrap-form==3.2.1, with Django==1.10.5.

drivard commented 7 years ago

Hi, I was getting the same issue in my project using Python 3.4.3 and I figured out that the issue is in the field.html template at line 50. I had to add the check on form.required_css_class into the if statement like the following <label class="control-label {{ classes.label }} {% if field.field.required and form.required_css_class %}{{ form.required_css_class }}{% endif %}" for="{{ field.auto_id }}">{{ field.label }}</label>.

I just can't explain the reason for it. The second problem is that this works without my change when running through python manage.py runserver in local dev environment, but once I deploy my code and that I run it through nginx and uwsgi it throws the same error as described here.

Any idea on why it just doesn't show or output the empty variable like it does in local dev?

drivard commented 7 years ago

More information about this issue, from the documentation here: https://docs.djangoproject.com/en/1.11/ref/forms/api/#styling-required-or-erroneous-form-rows to fix this issue without modifying django-bootstrap-form we had to add the following line to our form. required_css_class = 'required'. Hope it can help you fix your issue.