I don’t know why, but I couldn’t figure out how to activate jQuery on my website. All sites doing tutorials ‘Starting jQuery on Django’ started with JQuery already working on their site. Anyway, instead of downloading it and putting it in my folder somewhere, I decided to go the cheat-way and use Google’s.
Therefore, in my base page, I had the following piece of code
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js">
</script>
And everything worked great, until I had to add some libraries. How do I set up my own jQuery so that it works with my templates?
In the end, it turned out to be very easy. This is all one has to do:
First, make a folder named
staticinside your folder app:Then download jQuery from their site here. You click ‘Download’ and it will take you to a different page with all the code. Left click on the code and select ‘save as…’. Save it in the
staticfolder.Inside your
settings.pyfile make sure thatdjango.contrib.staticfilesis underINSTALLED_APPS(it is there by default).Lastly, inside your base page have
And now you can use jQuery throughout your site! (as long as the pages extend your basepage. If they don’t, they will need the above piece of code in their html.)
This works for me while working on my local machine. I haven’t tried actually deploying my site yet, so I hope this will still work.