title: Django: how do you serve media / stylesheets and link to them within templates
body: <p>Variations of this question have been asked, but I'm still unable to get my stylesheets to load correctly when my templates are rendered.</p>
  
  <p>I'm attempting to serve static media from the Django process during development - which is strongly discouraged in production, I'm aware. I'll post my configuration and my template, and hopefully someone can help me to understand where I'm going wrong.</p>
  
  <p>Note that I did try to follow the example on the Django project website, however it doesn't mention how to refer to your stylesheets from a template. I've also tried many different variations of the same thing, so my code/settings may be a little off from what's described.</p>
  
  <p>settings.py</p>
  
  <pre><code>MEDIA_ROOT = 'D:/Dev Tools/django_projects/dso/media'
  MEDIA_URL = '/media/'
  ADMIN_MEDIA_PREFIX = '/media/'
  </code></pre>
  
  <p>urls.py</p>
  
  <pre><code>from django.conf.urls.defaults import *
  from django.conf import settings
  from django.contrib import admin
  
  admin.autodiscover()
  
  urlpatterns = patterns('',
      (r'^admin/(.*)', admin.site.root),
      (r'^ovramt/$', 'dso.ovramt.views.index'),
  )
  
  if settings.DEBUG:
      urlpatterns += patterns('',
          (r'^media/(?P&lt;path&gt;.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
      )
  </code></pre>
  
  <p>Within my template:</p>
  
  <pre><code>&lt;head&gt; 
  &lt;title&gt; {% block title %} DSO Template {% endblock %} &lt;/title&gt; 
  &lt;meta http-equiv="Content-Type" content="text/html;charset=utf-8" &gt;
  &lt;link rel="stylesheet" type="text/css" href="../media/styles.css"&gt;
  &lt;/head&gt;
  </code></pre>
  
  <p>I assure you, the files (templates/media) are in the correct directory on my file system. If there's any extra information I need to provide, please post a comment.</p>
  
  <hr>
  
  <p>Edit:  </p>
  
  <p>One of the problems I was having was the use of a '/' prepending my links. If the forward slash is prepended, the link is opened from the root of the site. If there is no forward slash, the link is opened in the current level. An example:</p>
  
  <p>www.example.com/application/ has a link "/app2/ and a link "app3/".<br>
  app2 will open at www.example.com/app2/ and app3 will open at www.example.com/application/app3/. This was confusing me I think.</p>