0

In settings.py:

STATIC_ROOT = os.path.join(PROJECT_PATH, '..', 'media/static')
STATIC_URL = '/media/static/

In rendered page:

<title>Site administration | Django site admin</title>
<link rel="stylesheet" type="text/css" href="/media/static/admin/css/base.css" />
<link rel="stylesheet" type="text/css" href="css/dashboard.css" />

The href for base.css is right, but the href for dashboard.css is missing the media/static/admin. Why?

zoo
  • 1,901
  • 1
  • 17
  • 25

3 Answers3

0

I guess your template looks like this?

<title>Site administration | Django site admin</title>
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}admin/css/base.css" />
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/dashboard.css" />

Can you access both the files if you try opening them in your browser with the location that they should have? /media/static/admin/css/base.css and /media/static/css/dashboard.css (or maybe ../admin/...)

Have you added 'django.core.context_processors.static', to your TEMPLATE_CONTEXT_PROCESSORS?

UPDATE

It worked fine for me when I tried the same. In my template:

{% load staticfiles %}
<link rel="stylesheet" type="text/css" href="{% block stylesheet %}{% static "admin/css/base.css" %}{% endblock %}" />, 
<link rel="stylesheet" type="text/css" href="{% static "admin/css/dashboard.css" %}" />

The rendered HTML (in my current project /static/ is my STATIC_URL):

<link rel="stylesheet" type="text/css" href="/static/admin/css/base.css" />, 
<link rel="stylesheet" type="text/css" href="/static/admin/css/dashboard.css" />
olofom
  • 6,233
  • 11
  • 37
  • 50
  • @zoo what if you try my approach? Could you access the files? – olofom Jun 28 '12 at 08:06
  • Both files are accessible at /media/static/admin/css/. The question is why django.contrib.staticfiles is producing the right URL for base.css but not for dashboard.css. – zoo Jun 29 '12 at 06:32
  • @zoo I'm sure you've made some mistake in your code and it's hard to find without seeing more of it. See my updated answer for my results. – olofom Jun 29 '12 at 07:31
0

I've previously had some trouble with STATIC_URL when I forgot to set the context of render_to_response. Without seeing the code you use in your view and template it is quite hard to determine the actual problem, but if it's setting the context and you're using render_to_response, try the following:

return render_to_response("login.html", context_instance=RequestContext(request))

The same goes for a lot of other render functions. Could you post the view and template?

DZittersteyn
  • 628
  • 3
  • 8
  • If that were the case then no url would be rendered. Btw, I recommend using [render](https://docs.djangoproject.com/en/dev/topics/http/shortcuts/#render) instead of render_to_response. Then it would look like `return render(request, 'login.html', {})` – olofom Jun 29 '12 at 10:10
  • Yeah, I'm just trying to cover all the bases, as we know very little about the template and view. It's probably not this, but just in case. – DZittersteyn Jun 29 '12 at 10:16
0

Even though Django yells at you that ADMIN_MEDIA_PREFIX is deprecated, putting it in your settings.py seems to fix this error some of the time. I haven't had time to source dive, but wherever the 'extra_styles' context, where the dashboard.css comes from, is set still seems to look at the AMP setting.