tags:

views:

89

answers:

3

I've got a template, a.html, which looks like this:

<script type="text/javascript" src="jquery-1.4.min.js"></script>
<script type="text/javascript" src="reg.js"></script>

Why doesn't this work?

A: 

Because you didn't set up your web server to alias those to their corresponding static media.

Ignacio Vazquez-Abrams
A: 

Since your URLs can have arbitrary path depths, you need to get absolute path to your JS. e.g.

<script type="text/javascript" src="/js/jquery-1.4.min.js"></script>
<script type="text/javascript" src="/js/reg.js"></script>
sharjeel
Also, make sure you have those files setup at the said locations by adding something like (r'^(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.CORE_MEDIA_ROOT}),On production, the main webserver (apache or nginx etc.) should serve the content instead of your django application.Re
sharjeel
+3  A: 

Try:

<script type="text/javascript" src="{{ MEDIA_URL }}jquery-1.4.min.js"></script>
<script type="text/javascript" src="{{ MEDIA_URL }}reg.js"></script>

You'll need to make sure you're serving static files correctly, and you'll need "django.core.context_processors.media" in the TEMPLATE_CONTEXT_PROCESSORS setting.

Dominic Rodger