dev server cannot access javascript files in template

1 view
Skip to first unread message

Igor Ganapolsky

unread,
Mar 17, 2010, 5:30:19 PM3/17/10
to Django users
Hi,
I am running a django dev server. I have a template where I'm calling
a javascript function from a an external .js file (residing in the
same directory as the template). However, I get the following error:
"ReferenceError: al is not defined". Nevertheless, when I just open
this html page without the django dev server, the function al() works
fine.
I am puzzled by this. Does anybody have an idea?

Thanks

Daniel Roseman

unread,
Mar 17, 2010, 6:04:03 PM3/17/10
to Django users

Why is your javascript file in the same directory as the template? How
have you configured your server to serve static assets?
--
DR.

Igor Ganapolsky

unread,
Mar 17, 2010, 6:24:18 PM3/17/10
to Django users
I have since then moved my javascript file to a site_media/scripts
directory. My project structure looks like this:
webservice/
|-- first/
-- site_media/
-- scripts/
-- templates/
-- urlss/

What I have done is:
1) In urls.py I added (r'^site_media/(?P<path>.*)$',
'django.views.static.serve',{'document_root': 'first/site_media/
scripts', 'show_indexes': True})
2) In my view I have a render_to_response('TopicTree.html',
{'site_media':'first/site_media/scripts/'},
context_instance=RequestContext(request))
3) In my TopicTree.html template I have a <script type="text/
JavaScript" src="{{ site_media }}alert.js"></script>

Igor Ganapolsky

unread,
Mar 17, 2010, 6:42:50 PM3/17/10
to Django users
I should add that I still have the problem...
Reply all
Reply to author
Forward
0 new messages