在本地的时候,admin的css是在django的目录下的。当部署到服务器之后,这些静态文件路径需要修正。
方法是在服务器上 /etc/apache2/sites-enables/PersonalWebsite.conf里面写好 路径的Alias 并且 给目录赋予权限:
注意这里alias有先后,不然alias会重叠,就无效了。
WSGIScriptAlias / /home/ubuntu/PersonalWebsite/PersonalWebsite/wsgi.py WSGIPythonPath /home/ubuntu/PersonalWebsite <Directory /home/ubuntu/PersonalWebsite/PersonalWebsite> <Files wsgi.py> Order deny,allow Require all granted </Files> </Directory> Alias /media/ /home/ubuntu/PersonalWebsite/media/
Alias /static/admin/ /usr/local/lib/python2.7/dist-packages/django/contrib/admin/static/admin/
Alias /static/ /home/ubuntu/PersonalWebsite/static/
<Directory /usr/local/lib/python2.7/dist-packages/django/contrib/admin/static/admin>
Require all granted
</Directory>
<Directory /home/ubuntu/PersonalWebsite/static> Require all granted </Directory> <Directory /home/ubuntu/PersonalWebsite/media> Require all granted </Directory>