Graphite Tip - Django 1.4 Admin Workaround

2014-01-05 00:39:38 by jdixon

If you're using Graphite with Django 1.4 or newer, you've probably noticed the broken styling on the Admin module. This appears to be an annoyance at worst, but it's ugly nonetheless. I don't have a fix for this yet, but I have a workaround for anyone using Apache with their Graphite web UI.

This is what the view typically looks like when you visit /admin/ on your Graphite server.

Due to changes introduced in Django 1.4, the media (static content) files for the django.contrib.admin module where moved to a different directory. Graphite hasn't been updated to reflect these changes, so stylesheets like /admin/css/base.css aren't being loaded at all, resulting in something like this instead:

Fortunately, there's an easy workaround with Apache. Add the following directives to your relevant configuration block (I use a VirtualHost) and then restart your web service.

RedirectMatch ^/admin(.*)admin/([^/]+)/([^/]+)$ /media/$2/$3
Alias /media/ "/usr/share/pyshared/django/contrib/admin/static/admin/"

Comments

at 2014-01-05 07:39:07, ced wrote in to say...

Hi,

thanks for this tip.

Following is the syntax for nginx

at 2014-01-05 21:59:54, ced wrote in to say...

rewrite ^/admin(.*)admin/([^/]+)/([^/]+)$ /media/$2/$3 redirect;

location /media {

alias /usr/share/pyshared/django/contrib/admin/static/admin/;

}

PS : Forgot rules :/

at 2014-01-10 11:39:29, Victor E. Bazterra wrote in to say...

Hi Jason,

I found an alternative solution I think closer to the new way django manage static content (starting from version 1.4). I am using a graphite webapp version close to the current master, however I have my own repo for this:

https://github.com/graphite-server/graphite-web

What I did was to add the following lines to app_setting.py (I removed ADMIN_MEDIA_PREFIX) because I understand this is now deprecated).

---

# Absolute path to the directory that holds static content.

STATIC_ROOT = '/opt/graphite/webapp/content/'

# URL that handles the static content from STATIC_ROOT.

STATIC_URL = '/content/'

...

INSTALLED_APPS = (

...

'django.contrib.staticfiles',

...

)

---

see: https://github.com/graphite-server/graphite-web/blob/master/webapp/graphite/app_settings.py

Then you need to run manage.py with the option collectstatic

python manage.py collectstatic

This collects all the static content from contrib.admin into /content/admin/. Then you just need to restart django/appache server and admin static content should be servered.

at 2014-02-21 20:30:21, Deepak wrote in to say...

Missing one more rewrite for the datepicker in NGINX.

rewrite ^/admin(.*)admin/([^/]+)/([^/]+)/([^/]+)$ /media/$2/$3/$4 redirect;

rewrite ^/admin(.*)admin/([^/]+)/([^/]+)$ /media/$2/$3 redirect;

location /media {

alias /usr/lib/python2.6/site-packages/django/contrib/admin/static/admin/;

}

at 2014-05-08 16:20:13, anonymous wrote in to say...

@Victor E. Bazterra: your solution works great! (also tried the other one using the http redirect, did not work for me)

Add a comment:

  name

  email

  url

max length 4000 chars