Django with Jquery

88 views
Skip to first unread message

Alexis Selves

unread,
Feb 28, 2010, 12:39:04 PM2/28/10
to Django users
Hello,
I am totally helpless. I am trying to use JQuery in my django
templates, but I always get in firebug this: $ not defined.

In my template I am linking jquery :
<script type="text/javascript" src="jquery/jquery.js"></script>

And then
<script language="JavaScript" type="text/javascript">
$(document).ready(function() {
alert("Hello from jQuery");
});
</script>

But I always get nothing..
using ubuntu 9.10. Thanks for your help in advance.

Malcolm Box

unread,
Feb 28, 2010, 12:58:24 PM2/28/10
to django...@googlegroups.com
On Sun, Feb 28, 2010 at 5:39 PM, Alexis Selves <petr....@gmail.com> wrote:
Hello,
I am totally helpless. I am trying to use JQuery in my django
templates, but I always get in firebug this: $ not defined.

Check with Firebug if the jquery script has been successfully loaded (using either the CSS or Net tabs)
 
In my template I am linking jquery :
<script type="text/javascript" src="jquery/jquery.js"></script>

Are you sure this file is being correctly loaded in the browser?  Is this line showing up in the generated HTML?
 

But  I always get nothing..
using ubuntu 9.10. Thanks for your help in advance.

 
You don't get nothing, you get something that's just not what you expect.  It's much easier to help you debug if you tell us what you do get, and what steps you've taken to eliminate possibly sources of errors.

For example, in you situation I would check (and report on):

- whether the browser can load the page
- whether the <link> tag shows up in the browser (use "View Source" or Firebug)
- whether you can download the JQuery file manually at the location in the link
- whether the JQuery really was downloaded in the page (check using Firebug)

If all those tests were passed successfully then you've got a very different problem than if e.g. the browser can't load the page.

Hope this helps.

Malcolm

andreas schmid

unread,
Feb 28, 2010, 12:59:31 PM2/28/10
to django...@googlegroups.com
Alexis Selves wrote:
> Hello,
> I am totally helpless. I am trying to use JQuery in my django
> templates, but I always get in firebug this: $ not defined.
>
> In my template I am linking jquery :
> <script type="text/javascript" src="jquery/jquery.js"></script>
>
>
where do you have your static files? did you serve them as static files?
maybe ur only missing the slash to the js file path like
src="/jquery/jquery.js"

Romain Gaches

unread,
Mar 1, 2010, 2:13:36 AM3/1/10
to django...@googlegroups.com

Le 28 févr. 2010 à 18:39, Alexis Selves a écrit :

> Hello,
> I am totally helpless. I am trying to use JQuery in my django
> templates, but I always get in firebug this: $ not defined.

Did you try with 'jQuery' instead of '$' ?
If jQuery.no_conflict() was called, the $ variable isn't defined.

I always call no_conflict() to prevent any namespace collision with other JS Frameworks, especially with re-usable or partial code.

--
Romain Gaches
rom...@ssji.net

grimmus

unread,
Mar 1, 2010, 9:00:32 AM3/1/10
to Django users
link to the Google jQuery instead of a local file (it's really fast
too)

<script type="text/javascript" src="http://google.com/jsapi" />
<script type="text/javascript">
google.load('jquery','1.3.2');
</script>

Reply all
Reply to author
Forward
0 new messages