Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django-cms and jQuery

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...

like image 930
Ben Griffiths Avatar asked Nov 15 '10 12:11

Ben Griffiths


People also ask

Is Django good for CMS?

django CMS is user friendly and has a very intuitive drag and drop interface. It's built around the needs of multi-lingual publishing by default, not as an afterthought: all websites, pages and content can exist in multiple language versions.

What is django CMS used for?

django CMS is a free and open source content management system platform for publishing content on the World Wide Web and intranets.

Is Django admin CMS?

Django Admin is to CMS as printing lines out of a database is to a sales report. Sure, it can technically give them all the features they need... But its a bad user experience and definitely not for people who arne't tech inclined.


2 Answers

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.

like image 55
Ben Griffiths Avatar answered Sep 25 '22 11:09

Ben Griffiths


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.

like image 24
Agonych Avatar answered Sep 21 '22 11:09

Agonych