Question

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.

Was it helpful?

Solution

How about:

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

Can you see it being loaded in Firebug net tab?

OTHER TIPS

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

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> 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top