django-crispy-forms: Upgrading from 1.6.1 to 1.7.* - forms don't work

  • Package version: 1.7.2 (or 1.7.0 or 1.7.1)
  • Django version: 1.11.16
  • Python version: 3.5.2
  • Template pack: (Optional)

Description:

  • We upgraded Speedy Net from django-crispy-forms==1.6.1 to django-crispy-forms==1.7.2

  • We didn’t expect anything to change.

  • Our contact form stopped working in all 4 websites.

Preferably also include:

  • Example Django Crispy Forms code

The tag is {% crispy form %} on feedback_form.html

  • Screenshots

  • With django-crispy-forms==1.6.1: 2019-01-08_1949_speedy_net_-_contact_form_working

  • With django-crispy-forms==1.7.2:

2019-01-08_1947_speedy_net_-_contact_form_not_working

  • Actual HTML generated

There is no <textarea ... in the HTML with 1.7.0 up to 1.7.2.

  • Expected HTML

There is <textarea ... in the HTML with 1.6.1.

I can’t paste HTML into this issue, I tried.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 39

Commits related to this issue

Most upvoted comments

I would like to reopen this issue. It’s very easy to reproduce for me.

Let’s have a ModelForm and add a few custom fields to it

class MyModel(Model):
    field1 = models.CharField()

class MyForm(ModelForm):
    extra_field = forms.CharField()
   
    class Meta:
        model = MyModel
        fields = ('field1', 'extra_field')

If you render this form in Crispy Forms < 1.7.0 it works and renders both fields If you render this form in Crispy Forms >= 1.7.0 it renders field1 only

The reason is commit https://github.com/django-crispy-forms/django-crispy-forms/commit/6b93e8a362422db8fe54aa731319c7cbc39990ba which broke it. The ‘extra_field’ is neither required or hidden so it depends on render_unmentioned_fields which defaults to False. Since the field is mentioned in Meta.fields, it should be rendered. See also docs/form_helper.rst

By default django-crispy-forms renders the layout specified if it exists strictly, which means it only renders what the layout mentions unless your form has Meta.fields and Meta.exclude defined, in that case, it uses them. If you want to render unmentioned fields (all form fields), for example, if you are worried about forgetting mentioning them you have to set this property to True. It defaults to False.

I wonder why @ghinch committed this at all. If fields are mentioned in Meta.fields they should be unconditionally rendered, shouldn’t they?

and if I imported : from crispy_forms.helper import FormHelper

in the forms.py it will yield another error :

File “D:\installed_apps\python\lib\site-packages\crispy_forms\helper.py”, line 4, in <module> from django.core.urlresolvers import reverse, NoReverseMatch ModuleNotFoundError: No module named ‘django.core.urlresolvers’

it gives me error in th cmd :

django.template.library.InvalidTemplateLibrary: Invalid template library specifi ed. ImportError raised when trying to load ‘crispy_forms.templatetags.crispy_for ms_tags’: No module named ‘django.core.urlresolvers’ [09/Jan/2019 19:59:53] “GET / HTTP/1.1” 500 168519

I having the same issue , and I asked it on https://stackoverflow.com/questions/54101476/crispy-forms-and-bootstrap-styles?noredirect=1#comment95058861_54101476 and I hope any one could help me with it

Which versions of django-crispy-forms did you try using and did it work with any of them?

I’ve just instaleed it today, by pip install --upgrade django-crispy-forms i belive it is 1.7.2

I having the same issue , and I asked it on https://stackoverflow.com/questions/54101476/crispy-forms-and-bootstrap-styles?noredirect=1#comment95058861_54101476 and I hope any one could help me with it