How can I update jquery version in Django admin? Without replacing it in django/contrib/admin/media/js/admin/ jquery.min.js To newest jquery.min.js. Also I don't want to use two versions of jquery in my admin.
问题:
回答1:
That's your only two options. You're right about changing the actual Django file being a bad idea, so the only other option is to load your own in addition to that.
The Django version of jQuery is already namespaced as django.jQuery
, so you can load your own version of jQuery with or without jQuery.noConflict()
.
I understand you feelings toward running two versions of jQuery on the same page, but this is the admin site, not your user-facing website. It's not that much of a speed cost loading the library twice, but it will only even be applicable to the handle of users (or maybe just yourself) who use the admin.
回答2:
I had the same problem, and I found there are few ways to achieve it. Since django admin base template does not directly include jQuery JS (hardcoded in template) and relies on admin framework to supply it, I cannot override it in template. So, the other possible ways are -
With Django's new staticfiles app, you can apply command
collectstatic
to get all the static files in the app (including django.contrib.admin). You can manually override the content here. It would be better to overwrite a latest jquery-min version since django admin templates include the uncompressed jquery.You can use the ReWrite rule on deployed server to always point the jquery.js to some other url like jquery.latest.min.js where you keep a single copy of latest minified jquery. I would prefer this option.
Rewrite rules are defined here :
- Apache : http://httpd.apache.org/docs/current/mod/mod_rewrite.html
- Nginx : http://wiki.nginx.org/HttpRewriteModule