title: Javascript with Django?
body: <p>I know this has been asked before, but I'm having a hard time setting up JS on my Django web app, even though I'm reading the documentation.</p>
  
  <p>I'm running the Django dev server. My file structure looks like this:</p>
  
  <pre><code>mysite/
        __init__.py
        MySiteDB
        manage.py
        settings.py
        urls.py
        myapp/
             __init__.py
             admin.py
             models.py
             test.py
             views.py
             templates/
                  index.html
  </code></pre>
  
  <p>Where do I want to put the Javascript and CSS? I've tried it in a bunch of places, including <code>myapp/</code>, <code>templates/</code> and <code>mysite/</code>, but none seem to work.</p>
  
  <p>From <strong>index.html</strong>:</p>
  
  <pre><code>&lt;head&gt;
      &lt;title&gt;Degree Planner&lt;/title&gt;
      &lt;script type="text/javascript" src="/scripts/JQuery.js"&gt;&lt;/script&gt;
      &lt;script type="text/javascript" src="/media/scripts/sprintf.js"&gt;&lt;/script&gt;
      &lt;script type="text/javascript" src="/media/scripts/clientside.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  </code></pre>
  
  <p>From <strong>urls.py</strong>:</p>
  
  <pre><code>(r'^admin/', include(admin.site.urls)),
  (r'^media/(?P&lt;path&gt;.*)$', 'django.views.static.serve', {'document_root': 'media'})
  (r'^.*', 'mysite.myapp.views.index'),
  </code></pre>
  
  <p>I suspect that the <code>serve()</code> line is the cause of errors like:</p>
  
  <pre><code>TypeError at /admin/auth/
  'tuple' object is not callable
  </code></pre>
  
  <p>Just to round off the rampant flailing, I changed these settings in <strong>settings.py</strong>:</p>
  
  <pre><code>MEDIA_ROOT = '/media/'
  MEDIA_URL = 'http://127.0.0.1:8000/media'
  </code></pre>
  
  <p><strong>UPDATE</strong>: I made some changes, but it's still not working:</p>
  
  <p><strong>settings.py</strong>:</p>
  
  <pre><code>ROOT_PATH = os.path.normpath(os.path.dirname(__file__))
  </code></pre>
  
  <p><strong>urls.py</strong>:</p>
  
  <pre><code>(r'^media/(?P&lt;path&gt;.*)$', 'django.views.static.serve', {'document_root': os.path.join(settings.ROOT_PATH, 'site_media')}),
  </code></pre>
  
  <p><strong>index.html</strong>:</p>
  
  <pre><code>&lt;script type="text/javascript" src="/media/JQuery.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="/media/sprintf.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="/media/clientside.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <p><strong>Filesystem</strong>:</p>
  
  <pre><code>mysite/
        site_media/
                  JQuery.js
                  sprintf.js
                  clientside.js
        __init__.py
        settings.py
        manage.py
        -- etc
        myapp/
             -- app files, etc
  </code></pre>
  
  <p>When I go to a url like <code>http://127.0.0.1:8000/media/sprintf.js</code>, I get:</p>
  
  <pre><code>Page not found: /media/sprintf.js
  </code></pre>