Static Files not being displayed in Production

心不动则不痛 提交于 2019-12-08 21:44:46

First of all, it seems to me that your edited STATICFILES_DIRS points to the wrong folder, since you have /static/ folder, not /staticfiles/. Should be as it was originally:

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)

Second, STATIC_ROOT should point to the static folder which will be served by webserver in pro (but preferably not in project folder). In your case:

STATIC_ROOT="/opt/soundshelter/soundshelter/soundshelter/static/"

I usually place static folder near the project one and use dynamic STATIC_ROOT instead of hardcoding:

BASE_DIR = os.path.abspath(os.path.dirname(__file__))
#this will alow to collect your static files in /opt/soundshelter/soundshelter/staticfiles/static
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'staticfiles/static')

Now you should do collectstatic and it will collect all static files in the STATIC_ROOT directory.

BAD SOLUTION - DO NOT USE IN PRODUCTION

https://docs.djangoproject.com/en/1.8/howto/static-files/

Adding this to urls.py did the trick

from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    # ... the rest of your URLconf goes here ...
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

In your Nginx Config did you try to set:

location /static {

instead of

location /static/ {

also make sure the user running nginx has read permissions to the static folder.

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