Django missing admin CSS stylesheets
Follow up on three of my previous posts:
- How to install and configure mod_wsgi on FreeBSD 8.2
- How to install and configure Django with mod_wsgi on FreeBSD 8.2
- Install PostgreSQL on FreeBSD 8.2 and make it work with Django
I have been following the official Django tutorial and creating the polls app. I have decided to test my app in a FreeBSD virtual machine with properly configured Apache instead of the development server though.
I got to the part where I am supposed to log in into the automatically generated admin area. The http://IP_OF_MY_TEST_VM/admin/ works and I get the admin sign in page but the links to stylesheets are not working. It’s simple to fix that.
My app is located in /usr/local/www/myapp folder and it’s document root is set via httpd.conf to /usr/local/www/myapp/public directory. So:
#cd /usr/local/www/myapp/public #mkdir static #cd static #mkdir admin #cp -r /usr/local/lib/python2.7/site-packages/django/contrib/admin/media/* /usr/local/www/myapp/public/static/admin
That should copy free directories (css, img, js) into your document root. One more thing, edit your virtual host configuration to tell mod_wsgi to match /static/ to /usr/local/www/myapp/public/static/:
WSGIPythonPath /usr/local/www <VirtualHost *:80> ServerName localhost.home ServerAlias localhost.home DocumentRoot /usr/local/www/myapp/public Alias /static/ /usr/local/www/myapp/public/static/ <Directory /usr/local/www/myapp/public> Order allow,deny Allow from all </Directory> WSGIScriptAlias / /usr/local/www/myapp/wsgi.py <Directory /usr/local/www> Order allow,deny Allow from all </Directory> </VirtualHost>
Restart Apache:
#/usr/local/sbin/apachectl restart
And go to http://IP_OF_MY_TEST_VM/admin/. CSS stylesheets should now get loaded properly