Search code examples
djangostackato

Stackato not servering Django static files


I am deploying an Django app to Stackato. Everything works fine except static files. According to the documentation, here is my setting in .yml file:

processes:
  web: $STACKATO_UWSGI --static-map /static=$HOME/static

And here is my local setting.py:

STATIC_URL = '/static/'

STATICFILES_DIRS = (
    os.path.join(PROJECT_PATH, "static"),
    '/var/www/static/',
)

Also, here is my project structure

Project -- .....
           |
            static -- css
                  |
                   -- images

I did not see any error from the log. Any idea?


Solution

  • Just figured it out:

    1.While settings.DEBUG is set to True, static url pattern has to be included:

    from django.contrib.staticfiles.urls import staticfiles_urlpatterns
    if settings.DEBUG:
    urlpatterns += staticfiles_urlpatterns()
    

    2.Static files should follow this structure:

    Project -- <app 'Project'> -- settings.py
               |                  |
               |                  -- urls.py
               |                  |
               |                  -- wsgi.py
               |
               -- <app 'somename'> -- ..
                                |
                                -- static -- <app 'somename'> -- css - a.css
                                                              |
                                                              -- images - a.jpg
    

    3.STATIC_ROOT should not be the actual location of static directory, which could be as this: Project/Project/static, while STATICFILES_DIRS has to be the actual static files directory which is Project/somename app/static

    Reference: https://github.com/mozilla/mozmoderator