Django static files do not display in production server. How can I map them correctly, so I can see the admin GUI

Deadly 提交于 2019-12-08 08:38:54

问题


I am running a django project off of an Ubuntu Server 14.04, the web page is up and running, however when the page loads, there is no CSS, or format at all, it just looks like plain HTML. I know for sure that the admin page has a style and aesthetic, and even that looks like plain HTML. What did I do wrong? Maybe I didn't collect the static files correctly?

Picture of the page:

Not sure why this is happening

Apache error.log:


回答1:


did you set the STATIC_ROOT in your projects settings , then make collect static and add the folder name in apache conf.

eg :

STATIC_URL = '/static/'
STATIC_ROOT = root("statticstorage")

then if run python manage.py collect static the command will create a folder called static storage and all the styles (including admin css and etc) will copied from static folder , then make the root in to static storage in apache conf




回答2:


I realized that I was mapping the static files incorrectly in apache.conf

The correct map to the files would be: Alias /static /var/www/html/myproject/static

Note: Need to make sure that /static doesn't have a trailing slash in the above command



来源:https://stackoverflow.com/questions/37313485/django-static-files-do-not-display-in-production-server-how-can-i-map-them-corr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!