Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django admin has no style

I have just moved my django site on my staging server, and the admin side of the site has no styling with it, when previously in local development it was fine, I read somewhere that I need to create a symbolic link, I did that by doing this

sudo ln -s /var/www/sico/htdocs /usr/lib/python2.5/site-packages/django/contrib/admin/

but that has done nothing is there anything else that I can try?

like image 981
Udders Avatar asked Dec 02 '09 15:12

Udders


2 Answers

Depending on your web server setup, you can do it one of two ways:

Symlinking

In your website's root folder, you should create a symbolic link to your Django admin media directory, with the name name as the ADMIN_MEDIA_PREFIX in your Django app's settings. By default this is /media/, so in your web root folder, create a symlink called media to /usr/lib/python2.5/site-packages/django/contrib/admin/media. (Note the trailing media on the end of the symlink, which is missing from your own example -- the Django admin media is located in a media subdirectoryincontrib/admin`).

Apache Alias

If your production server is Apache, and you can change the root configuration, you can use mod_alias to set up the path to Django admin media. Again, assuming that your ADMIN_MEDIA_PREFIX is /media/, you can set up an alias like so:

<VirtualHost *:80>
  Alias /media/ /usr/local/lib/python2.5/site-packages/django/contrib/admin/media/
</VirtualHost>

This way, all requests under the path /media/ will be resolved to that directory.

A similar technique exists for most other servers, such as Lighttpd or nginx; consult your server's documentation if you don't use Apache.


The solution using Apache's mod_alias is probably best for deployment, but the symlinking approach works just as well too.

The reason your app worked on your staging server is most likely because it was running with Django's internal web server, which can automatically resolve the path to the admin media directory.

like image 74
mipadi Avatar answered Sep 25 '22 08:09

mipadi


I think you've created the symlink the wrong way round - your command has created a htdocs symlink in ..../contrib/admin/

What you need is something like

sudo ln -s /usr/lib/python2.5/site-packages/django/contrib/admin/ /var/www/sico/htdocs/X

Where X is whatever you need to get to your ADMIN_MEDIA_PREFIX. I think the default would be admin/media

Hope that helps

like image 21
Aaron Lockey Avatar answered Sep 25 '22 08:09

Aaron Lockey