I've got a django site running quite happily with django-cms but now I want to include some of my own fancy javascript using jQuery. I'm rather new to django, so my problems might stem from this.
Django-cms uses jQuery itself, and so if I add jquery to the header - things break rathter unsurprisingly. How do I add my own jQuery without affecting django-cms?
At the moment my javascript files are stored in the media root which I've defined in the projects settings.py and, as mentioned, I reference them in the header.
As I read this, it seems a silly question, but I'm still perplexed.
EDIT::Some Code
I have a media root defined:
MEDIA_ROOT = os.path.join(PROJECT_PATH, 'media')
and in my base template the header includes
<script src="/media/javascript/jquery.js" type="text/javascript"></script>
<script src="/media/javascript/application.开发者_开发技巧js" type="text/javascript"></script>
Javascript in application.js works, but it when the django-cms stuff is up it breaks. For example, trying to add a plugin to a placeholder results in:
Uncaught TypeError: Property 'type' of object function ( selector, context ) {
// The jQuery object is actually just the init constructor 'enhanced'
return new jQuery.fn.init( selector, context );
} is not a function
I assumed this was because the two jQuerys were conflicting with each other
::ANOTHER EDIT:: I should probably add that I'm using django to host the static files only because this is still in development...
Well, linking the django-cms's bundled jQuery does fix everything...
Alas, it uses version 1.3.2 but I think I'll deal with that rather than try and upgrade django-cms for now.
A simple solution: keep your JQuery library in the header and place all other your JS at the boottom of the page, right before </body>
. In this case in admin mode, your jQuery lib will be overrided by admin's copy, and then all of your code will be added back to it.
精彩评论