0

I've been trying all sorts of things and can't figure this out!

For some reason on the Django development server the paths to the JavaScript just don't work.

Directory structure is

             site
               |
 appName    static      templates
    |          |            |
 views.py  javascript    appName
               |            |
            script.js     index.html

In index.html I have

<script type="text/javascript" src=../../static/javascript/script.js></script>

And it doesn't work!

If I copy and paste the script.js directly into index.html all of the functionality works, just the pathing is messed up.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
DevDevDev
  • 5,107
  • 7
  • 55
  • 87
  • What URL path is your index.html at? http://yourhost/index.html? Are you using Apache? Does the DocumentRoot for that host point to `site`? What are your MEDIA_ROOT and MEDIA_URL settings variables set to? – James Wheare Aug 26 '09 at 18:54

3 Answers3

3

Django does not serve static assets by default. It is possible to make it do it, in the development environment only - see the documentation.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
2

How about:

src="/static/javascript/..."

Can you see it being loaded in Firebug net tab?

meder omuraliev
  • 183,342
  • 71
  • 393
  • 434
  • Also when I expand the javascript tab for the loaded document I get the "Django error" replace DEBUG to get 404 thing. – DevDevDev Aug 26 '09 at 18:56
  • do any of your media resources work ( css, js )? Every request is routed to the django controller by default unless you explicitly specify some type of media directory and tell it to not go there. http://docs.djangoproject.com/en/dev/howto/static-files/ – meder omuraliev Aug 26 '09 at 18:59
0

What are your MEDIA values in settings.py? I have the following and they work fine on the dev server:

#settings.py
MEDIA_ROOT = 'C:/site/static'
MEDIA_URL = ''

Project structure:

C:/site/
    settings.py
    static/
        javascript/
            script.js
    templates/
    urls.py

In any of your templates:

<script type="text/javascript" src="/static/javascript/script.js"></script> 
Thierry Lam
  • 45,304
  • 42
  • 117
  • 144