5

For some reason, at some point the django administration got broken. The css is missing.

Here are my settings:

MEDIA_ROOT = os.path.normpath(os.path.join(SITE_ROOT, 'media/'))
MEDIA_URL = '/media/'
ADMIN_MEDIA_PREFIX = '/admin_media/'

However, the generated line on the admin page is still:

<link rel="stylesheet" type="text/css" href="/admin_media/css/base.css" />

but the site gives me 404 on this file.

And it gets better - if I use apache to view the project, that problem occurs. If I use python manage.py runserver the admin works well.

Any clues to why that might be happening? - restarted apache, that didn't help.

here is what i have in the urls file:

    (r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
2
  • 2
    Are you serving the static media files through Django or are you serving them through Apache? If the latter, you might want to show how you set up thoses files under the Apache configuration. Commented Dec 8, 2010 at 16:32
  • if you tell me how to understand the answer, i will figure out and tell you Commented Dec 8, 2010 at 20:25

1 Answer 1

9

Ok, I figured it out.

For production server, you have to setup a link to the setting you provided. For me, i chose admin_media folder, in the settings.py file:

ADMIN_MEDIA_PREFIX = '/admin_media/'

And in order to tell apache to look for files, you have to edit your sites-enabled file by adding the line:

Alias /admin_media/ /usr/lib/python2.6/dist-packages/django/contrib/admin/media/

Note though, that this is the path to the django contrib admin as installed on my server. Your server might have a different installation, so look up your settings. find out where your python is installed by copy pasting this in terminal:

python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"

Good luck to everybody!

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks, this was a really useful post. I created a symlink from the ADMIN_MEDIA_PREFIX to [Python]/dist-packages/django/contrib/admin/media/ and this also worked, without having to edit the Apache virtual host file.
Well written. Fixed the exact same problem I had.
It's worth mentioning that on Django 1.4.2 the path is different. It must be pointed to /usr/local/lib/python2.6/dist-packages/django/contrib/admin/static/admin/
The path for Django 1.4.3 in my Fedora 17 system: /usr/lib/python2.7/site-packages/django/contrib/admin/static/admin/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.