let's tame jQuery imports #1592

merged 4 commits into from Jan 17, 2013


None yet

2 participants


These two tiny changes have saved me from a world of pain and misery. I actually cried because of the problems that this pull request addresses.

The changes do two things:


Summary: stop importing jquery.js.min in PlaceholderAdmin(ModelAdmin).Media.

Django's own ModelAdmin already calls in jQuery; so we shouldn't try to import the same thing. (I say 'try' because actually we don't even do that correctly - see the second paragraph at #1584/.)

Importing jquery.js.min breaks attempts to make one's own admin/base_site.html provide a newer jQuery where it's needed.


Summary: create a {% block jquery %} around <script type="text/javascript" src="{% admin_static_url %}js/jquery.min.js"></script> in cms/templates/admin/cms/page/plugin_change_form.html.

A similar issue. The plugin_change_form.html extends admin/base_site.html, and loads jQuery. Now suppose your plugin needs a newer jQuery - there is no way to make that work without removing the jQuery here.

By putting it in a {% block jquery %}, it's now possible for your plugin's form to point at a template that extends plugin_change_form.html and overrides that block with the jQuery you want. Or, if your own admin/base_site.html already imports the jQuery you need, a simple {% block jquery %}{% endblock %} will prevent the undesired one from being loaded.

Breaks no tests, though I'm not sure how to test for this exactly. Works in practice as described above, on both a PlaceholderAdmin-based admin, and on a plugin.

Saved me from tears.

Divio AG member

looks good to me!


OK, don't merge this just yet, I'll add something for the documentation.

Divio AG member

docs also look fine to me :)

@evildmp evildmp merged commit e1bd3ee into divio:develop Jan 17, 2013
@evildmp evildmp deleted the evildmp:save-me-from-jquery-hell branch Jul 10, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment