Search code examples
djangodjango-staticfilesdjango-static

Django Debug False server 500, ValueError The file 'css/styles.css' could not be found


Today I deployed my project on a hosting server and since I have DEBUG = False I have an internal server error too. The full report is:

/storage.py", line 280, in stored_name
    cache_name = self.clean_name(self.hashed_name(name))
    File "/home/ttipprotest/lib/python3.4/django/contrib/staticfiles
/storage.py", line 94, in hashed_name
    (clean_name, self))
    ValueError: The file 'css/styles.css' could not be found with 
<django.contrib.staticfiles.storage.ManifestStaticFilesStorage object at 
0x7f2787c23ef0>.

Everything was working fine in developement, but now I am trying to solve this problem during the whole day. Sorry for displaying the error message that bad.

EDIT:

in prod settings:

BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

STATIC_URL = '/static/'
STATIC_ROOT = "/home/ttipprotest/webapps/ttipprotest_static/"
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static', 'our_static'),
)

MEDIA_URL = '/media/'
MEDIA_ROOT = "/home/ttipprotest/webapps/ttipprotest_media/"

Project structure:

src
-ttipprotest
--manage.py
--settings
---base.py
---prod.py
-app 1
-...
-app n
-static
--our static
---css
---js
---fonts
-templates

SECOND EDIT:

The problem appears every time when it comes to rendering a template it seems. Here is the index.html. I guess it is the source of this behavior since I figured out that other applications without this index.html are working fine.

{% load staticfiles %}
{% load crispy_forms_tags %}

Solution

  • Found the mistake while I was making the edit.

    In index.html:

    {% load staticfiles %}
    

    was perfectly working fine with DEBUG = True. At least it was rendering and showing the template, but in the logfile where shown errors. index.html is the template mostly every other template extends on.

    After I changed index.html to:

    {% load static %}
    

    it is working fine with DEBUG = False