views:

121

answers:

3

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 fucntionality works, just the pathing is messed up.

Thanks!

+2  A: 

How about:

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

Can you see it being loaded in Firebug net tab?

meder
I tried that it didn't work.
DevDevDev
Also when I expand the javascript tab for the loaded document I get the "Django error" replace DEBUG to get 404 thing.
DevDevDev
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
The link you posted did the trick.
DevDevDev
+2  A: 

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
A: 

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