1

I'm in desperate need of help. I have followed many tutorials, as well as scrutinized this, this, this, and this article. I was getting error messages when following the Django documentation for static servers mentioned in the middle two articles, but I seem to be doing all the right things discussed in the two regarding settings.py, placing jquery.js in the correct directory and referencing the correct source in the actual html file.

My media directory seems to be being referenced - the css file in there is working splendidly, and if I go to http://127.0.0.1:8000/media/jquery.js, the jquery file is displayed.

Still, none of my functions that I've built after following multiple tutorials work for me on my django project. I've been banging my head against the wall for days - please help if you can.

Django App Project File:

__init__.py
data.db
javascript_app/
manage.py
media/
settings.py
templates/
urls.py
views.py

Javascript App Directory:

__init__.py
admin.py
models.py
tests.py
urls.py
views.py

Media Directory:

jquery.js
style_js.css

Templates Directory:

javascript_app/

base.html
note_list.html

In my main settings file:

import os.path
ROOT_PATH = os.path.dirname(__file__)

...
MEDIA_ROOT = os.path.join(os.path.dirname(__file__), "media")
MEDIA_URL = 'http://127.0.0.1:8000/media/'
ADMIN_MEDIA_PREFIX = '/media/admin/'

In my main urls file:

from django.conf.urls.defaults import *
from django.views.static import *
from django.conf import settings
...
urlpatterns = patterns('',
(r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT }),

Desperately, I also put a media reference in my javascript_app 's urls.py (with the above-referenced import commands as well):

urlpatterns = patterns('',
(r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT }),

In templates/javascript/base.html:

<head>
<title>{% block title %}Notes Application{% endblock %}</title>
<link rel="stylesheet" href="/media/style_js.css">
<script type="text/javascript" src="/jennystanchak/media/jquery.js"></script>
</head>

And finally in templates/javascript/note_list.html:

{% extends "javascript/base.html" %}
{% block content %}
...
<script>
// my script here
</script>
{% endblock %}

What in the configuration am I missing??

Thank you SO MUCH in advance for your help :)
-- An aspiring female programmer

Community
  • 1
  • 1
Jenny
  • 11
  • 2
  • 1
    Why this: src="/jennystanchak/media/jquery.js" ? – Marco Feb 13 '11 at 05:32
  • An article I read on stack overflow suggested tacking on the directory file (jennystanchak is the django project name). When I have src="/media/jquery.js", the javascript still doesn't work. – Jenny Feb 13 '11 at 18:21
  • Could you paste the rendered html of your page. I mean the output of view source in your web browser. – Eric Fortin Feb 14 '11 at 03:24
  • the project name does not belong there - as Eric points out. Have you tried to view the page with firebug? If you go to the console in firebug and type $("*") what do you see? – Marco Feb 14 '11 at 07:43

1 Answers1

1
<script type="text/javascript" src="/jennystanchak/media/jquery.js"></script>

Shouldn't the path be src="/media/jquery.js" without /jennystanchak ?

Eric Fortin
  • 7,533
  • 2
  • 25
  • 33