title: Hosting Admin Media Locally During Development
body: <p>Consider the following setup:</p>
  
  <p><strong>urls.py</strong></p>
  
  <pre><code>if not settings.PRODUCTION:
      urlpatterns += patterns('',
          (r'^admin-media/(?P&lt;path&gt;.*)$', 'django.views.static.serve',{'document_root': settings.LOCAL_ADMIN_MEDIA_ROOT, 'show_indexes': True}),
          (r'^media/(?P&lt;path&gt;.*)$', 'django.views.static.serve',{'document_root': settings.LOCAL_MEDIA_ROOT, 'show_indexes': True}),
      )
  </code></pre>
  
  <p><strong>settings.py</strong></p>
  
  <pre><code>if not PRODUCTION:
      ADMIN_MEDIA_PREFIX = '/admin-media/'
  </code></pre>
  
  <p>So when running on the local development server the media files should be served through the runserver, right?  The media route is found, however "Permission denied" is returned for every request (but only one admin media, the regular media works fine).</p>
  
  <p>So I did some checking into it.  It turns out, if the <code>ADMIN_MEDIA_PREFIX</code> is set to the same value as the route...</p>
  
  <pre><code>(r'^admin-media/(?P&lt;path&gt;.*)$', 'django.views.static.serve', ... ),
  ADMIN_MEDIA_PREFIX = '/admin-media/'
  </code></pre>
  
  <p>...then the runserver will <em>always</em> return "Permission denied."</p>
  
  <p>However, if <code>ADMIN_MEDIA_PREFIX</code> is different than the route name...</p>
  
  <pre><code>(r'^admin-media/(?P&lt;path&gt;.*)$', 'django.views.static.serve', ... ),
  ADMIN_MEDIA_PREFIX = '/non-sense-prefix/'
  </code></pre>
  
  <p>... then the files will be served (though I have to manually browse to be able to see them as all the media links are broken with <a href="http://localhost:8000/non-sense-prefix/whatever.jpg" rel="nofollow noreferrer">http://localhost:8000/non-sense-prefix/whatever.jpg</a>).</p>
  
  <p><strong>What's the deal here?</strong></p>
  
  <p>In the mean time I've solved the problem by a little hack to change directories...</p>
  
  <pre><code>(r'^admin-media/(?P&lt;path&gt;.*)$', 'django.views.static.serve', ... ),
  ADMIN_MEDIA_PREFIX = '/admin-media/../admin-media/'
  </code></pre>
  
  <p>...but I would really rather configure this properly.  It seems django is trying to be smart and do something on my behalf, but messing things up in the process.  Any ideas?</p>
  
  <p><strong>EDIT</strong> --
  I'm manually serving the admin media because I'm using grappelli which provides replacement for the admin templates/media.</p>