Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Admin has broken CSS link through apache, but works in runserver mode

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}),
like image 571
mgPePe Avatar asked Dec 08 '10 16:12

mgPePe


1 Answers

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!

like image 143
mgPePe Avatar answered Oct 08 '22 21:10

mgPePe