Problem with Jquery over Django

34 views
Skip to first unread message

Amr Abdel-wahab

unread,
May 16, 2012, 11:56:00 AM5/16/12
to Django users
That's an example of a code, this exact file works fine if I just
double clicked it, but if when I render that HTML from a django view
the java scripts stops, This is really odd because the same exact file
runs out side the project if I just double clicked it as a HTML file,
but if I just try to open it from inside the scripts stops

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /
>
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
var flashvars = {};
var params = {};
var attributes = {};
attributes.id = "myId";
swfobject.embedSWF("/home/amr/STIP/media/MCCdirnum_2.swf",
"myAlternativeContent", "800", "600", "9.0.0", false, flashvars,
params, attributes);
</script>
</head>
<body>
<div id="myAlternativeContent">
<a href="http://www.adobe.com/go/getflashplayer">
<img src="http://www.adobe.com/images/shared/download_buttons/
get_flash_player.gif" alt="Get Adobe Flash player" />
</a>
</div>
</body>
</html>

Marcin Tustin

unread,
May 16, 2012, 11:57:30 AM5/16/12
to django...@googlegroups.com
You have a relative url for your JS. This is expanded to a different location depending on where it is served from.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.




--
Marcin Tustin
Tel: 07773 787 105

Amr Abdel-wahab

unread,
May 16, 2012, 12:02:18 PM5/16/12
to Django users
Man it's the same exact file, from the same directory and everything

Amr Abdel-wahab

unread,
May 16, 2012, 12:03:02 PM5/16/12
to Django users
It just doesn't work if rendered but the same exact file does work if
I opened it in a browser view

Marcin Tustin

unread,
May 16, 2012, 12:13:28 PM5/16/12
to django...@googlegroups.com
Once again:  You have a relative url for your JS. This is expanded to a different location depending on where it is served from. 

This means that in one case, your browser can find the file on the filesystem, but in the other, it tries to pull it from your server.

On Wed, May 16, 2012 at 5:03 PM, Amr Abdel-wahab <amr.mohamed...@gmail.com> wrote:
It just doesn't work if rendered but the same exact file does work if
I opened it in a browser view
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Amr Abdel-wahab

unread,
May 16, 2012, 12:15:27 PM5/16/12
to django...@googlegroups.com
Oh ok, then can you give me a solution?

Amr Abdel-wahab

unread,
May 16, 2012, 12:18:14 PM5/16/12
to django...@googlegroups.com
And I am sorry for bothering you.

Marcin Tustin

unread,
May 16, 2012, 12:18:28 PM5/16/12
to django...@googlegroups.com
Host your JS on your server, and use an absolute URL. This is what the STATIC_URL setting is for.

On Wed, May 16, 2012 at 5:15 PM, Amr Abdel-wahab <amr.mohamed...@gmail.com> wrote:
Oh ok, then can you give me a solution?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Phang Mulianto

unread,
May 16, 2012, 12:38:12 PM5/16/12
to django...@googlegroups.com

Hi

You need understand the different between open the html directly in you browser with open it from a web server.

Check your static file setting and load it, is it returning the js or not

Amr Abdel-wahab

unread,
May 16, 2012, 12:51:51 PM5/16/12
to django...@googlegroups.com
Ok to solve that thing quickly for now I just copied the whole JS file into my HTML, another problem we're facing here is that I get the name of the file dynamically  like the following

swfobject.embedSWF("{{lecture.lectureFile}}", "myAlternativeContent", "800", "600", "9.0.0", false, flashvars, params, attributes);

so now the file isn't working, although in the page source it shows the same URL of the file in the media root.

I know I am very bothering cause I am soo new to Django but I really have to finish this part.

Jon Paugh

unread,
May 16, 2012, 8:47:16 PM5/16/12
to django...@googlegroups.com
Check out "How to handle static files" from this page: https://docs.djangoproject.com/en/1.4/#the-development-process. Also note that the links on this page can help answer a lot of the basic questions about Django for you.

Django has a built-in app to handle static files, and cases such as this. You will need to do a lot of reading, and it will take a while to get it set up properly, but it will save you time in the long run. (This really is the easy way.)
Reply all
Reply to author
Forward
0 new messages