Question

I have a weird issue - my dev server trying to serve admin static by using a wrong url.

using django 1.6

my main urlconf

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
   url(r'^admin/', include(admin.site.urls)),
   url(r'^$', include('dash.urls')),
   )


urlpatterns += staticfiles_urlpatterns()

and settings are like

BASE_DIR = os.path.dirname(os.path.dirname(__file__))
locale = lambda path: os.path.join(BASE_DIR, path)
STATIC_URL = "static/"
MEDIA_URL = "media/"
STATIC_ROOT = locale("static")
MEDIA_ROOT = locale("media")

apps

INSTALLED_APPS = (
  'django.contrib.staticfiles',
  'django.contrib.admin',
)

the weird thing is that my custom apps serves static normaly by urls like localhost:8000/static/css/blah

but the admin one uses

[24/Nov/2013 18:47:41] "GET /admin/static/admin/css/base.css HTTP/1.1" 404 4316

Guys, seriously, what is the origin of prefix /admin/static? 0_o I am nat using deprecated stuff like ADMIN_MEDIA_PREFIX.

Base admin template uses {% static "admin/css/base.css" %} tag, which code is

from django.conf import settings
from django.template import Library

register = Library()

if 'django.contrib.staticfiles' in settings.INSTALLED_APPS:
    from django.contrib.staticfiles.templatetags.staticfiles import static
else:
    from django.templatetags.static import static

static = register.simple_tag(static)

which seams ok;

I am confused, help me)

Was it helpful?

Solution

Your STATIC_URL does not start with a slash so it is treated as a relative URL. Hence you'll get:

  • /admin/ (which is where the admin is),
  • static/ (your STATIC_URL), and
  • admin/css/base.css (which is where the file is).

In other words, that's why it's requesting /admin/static/admin/css/base.css.

You should add a slash to your STATIC_URL to make it request /static/admin/css/base.css.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top