question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Crispy filter does not include form media after 1.6.0 release

See original GitHub issue

The crispy filter does not include a form’s media anymore since release 1.6.0. This appears to be a bug as in the previous release, 1.5.2, the crispy filter when applied to a form or formset’s context variable would include the form’s media when rendered.

In the template

{% load crispy_forms_filters %}
...
{{ form|crispy }}

Form class

class MyForm(forms.Form):
    date=forms.DateField(
        label='Approved',
        required=True,
        widget=DatePlaceholder,
     )
...

The date field uses a widget that requires some javaScript and CSS to work correctly. These files are included in the form’s media when constructed in the view.

In version 1.5.2, this media would be included in the rendered html as seen below:

<link href="/path/to/jquery-ui-1.8.18.custom.css" type="text/css" media="all" rel="stylesheet">
<link href="/path/to/jquery-ui.css" type="text/css" media="all" rel="stylesheet">
<link href="/path/to/autocompleteselects.css" type="text/css" media="all" rel="stylesheet">
<script type="text/javascript" src="/path/to/jquery.autocompleteselects.js"></script>

<div id="div_id_approved_date" class="control-group"> 
    <label for="id_approved_date" class="control-label ">
         Approved
    </label>
    <div class="controls">
        <input class="dateinputwithplaceholder input-block-level" id="id_approved_date" name="approved_date" placeholder="mm/dd/yyyy" type="text">
    </div>
</div>

However, when using version 1.6.0, without changing any code, this is the rendered html:

<div id="div_id_approved_date" class="control-group"> 
    <label for="id_approved_date" class="control-label ">
         Approved
    </label>
    <div class="controls">
        <input class="dateinputwithplaceholder input-block-level" id="id_approved_date" name="approved_date" placeholder="mm/dd/yyyy" type="text">
    </div>
</div>

As you can see, the form media is no longer being included when being rendered by the filter.

This seems like it is a bug introduced between release 1.5.2 and 1.6.0. It initially seems like this could be related to the changes from #525 with the optional inclusion of form media when using the crispy template tag. Perhaps the include_media context variable is not being set correctly.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:7

github_iconTop GitHub Comments

1reaction
carltongibsoncommented, Nov 29, 2016

(Initially leaning towards “Yes” — not least to encourage people not to use it 🙂)

1reaction
troyshucommented, Nov 29, 2016

Thanks for pointing that out! In my form, self.helper.include_media is True, not from me setting it, but just from the initialization of self.helper with self.helper = FormHelper().

I, like the original poster, was using the filter to render a form{{ form|crispy }}, perhaps mistakingly. The issue goes away (i.e. the form media is rendered) when I use the crispy tag {% crispy form %} to show my form. Is that the desired behavior?

Read more comments on GitHub >

github_iconTop Results From Across the Web

django-crispy-forms Documentation
crispy -forms does not include static files. You will need to include the proper corresponding media files yourself.
Read more >
django crispy form button not showing - Stack Overflow
I'm using Django 1.11.9 and django-crispy-forms 1.7.0. You're on the right track, you actually want to add the 'submit' button in init for ......
Read more >
Advancing the Blog: 9 - Django Crispy Forms - YouTube
Advancing the Blog: 9 - Django Crispy Forms ** Advancing the Blog ** is an extended look at building a modern blog with...
Read more >
crispy-tailwind - PyPI
A tailwind package for Django Crispy Forms. ... Released: Apr 14, 2021 ... You will need to update your project's settings file to...
Read more >
[Solved]-Query over form.helper for Django-crispy-forms-django
Receiving 'invalid form: crispy' error when trying to use crispy forms filter on a form in Django, but only in one django app...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found