I make a Django admin site using Django development version
But it does not have a CSS style :
If you have a value set in settings.py for STATICFILES_DIRS and the declared folder doesn't exist or in wrong location it will cause the Admin to have no styling e.g by defining STATICFILES_DIRS = ( os.path.join(BASE_DIR,"static")) and the static folder doesn't exist
After setting up your STATIC_ROOT
and STATIC_URL
, you may have to run
python manage.py collectstatic
this works fine and easily. I moved (manually) the folder. just you have to copy your static/admin
from the directory of the main Project and paste it into public_html static/
if there is no static folder you have to run following command in terminal
python manage.py collectstatic
here you go with css working of Django admin
Admin panel was working fine except css wasn't loaded. This worked for Lightsail Django with Apache
1.Define STATIC_ROOT and STATIC_URL in settings.py
STATIC_ROOT = '/opt/bitnami/projects/decisions/decision/'
STATIC_URL = '/static/'
2.Eject(copy) admin assets files to the project
run python manage.py collectstatic
this command creates /opt/bitnami/projects/decisions/decision/admin
folder with css/
fonts/
img/
js/
subfolders
3.Make /static url accessible from apache
Paste this snippet in /opt/bitnami/apache2/conf/bitnami/bitnami.conf
(If you have set up ssl then the file location will be /opt/bitnami/apache2/conf/bitnami/bitnami-ssl.conf
)
Alias /static/ "/opt/bitnami/projects/decisions/decision/"
<Directory "/opt/bitnami/projects/decisions/decision/">
Order allow,deny
Options Indexes
Allow from all
IndexOptions FancyIndexing
</Directory>
4. Don't forget to restart apache
sudo /opt/bitnami/ctlscript.sh restart apache
Same sort of issue i encountered while developing a site in django-1.10.5 and python-2.7.13. But in my firefox-51 and chrome, the login page was able to get the css but still there was no styling. But weirdly it was working on IE-8..
I tried do every possible thing mentioned here and suitable to my set of sw versions. None worked.
But when i tried the same site on other system which had the python-2.7.8, it worked..
Just posted if it may help someone...
edited: later I found that in python-2.7.13, writing the following two lines in settings.py (plus clearing the cache of the browser) had done the trick
import mimetypes
mimetypes.add_type("text/css", ".css", True)
run: python manage.py collectstatic
Add this line to Vhost which located at : /etc/apache2/sites-available/000-default.conf
Alias /static/admin/ /var/www/html/example.com/static/admin
Here is entire Vhost setting for django setup
<VirtualHost *:80>
ServerName gautam.tech
ServerAlias www.gautam.tech
WSGIDaemonProcess gautam.tech python-path=/var/www/html/gautam.tech python-home=/var/www/html/gautam.tech/venv
WSGIProcessGroup gautam.tech
#Your static files location
Alias /static /var/www/html/gautam.tech/static
Alias /media/ /var/www/html/gautam.tech/media
Alias /static/admin/ /var/www/html/gautam.tech/static/admin
<Directory /var/www/html/gautam.tech/static>
Require all granted
</Directory>
<Directory /var/www/html/gautam.tech/media>
Require all granted
</Directory>
WSGIScriptAlias / /var/www/html/gautam.tech/myproject/wsgi.py
DocumentRoot /var/www/html/gautam.tech
<Directory /var/www/html/gautam.tech>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
CustomLog /var/www/html/gautam.tech/access.log combined
ErrorLog /var/www/html/gautam.tech/error.log
</VirtualHost>
This will work for sure!