Gunicorn cant find the static files

Viewed 617

By using gunicorn without nginx from digitalcloud tutorial my server is runing and on the console is

not found: /static/style.css

settings.py

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')

I already tried to

  1. collectstatic

  2. do urlpatterns += staticfiles_urlpatterns() in urls.py file

  3. makemigrations + migrate

3 Answers

maybe django try read 'static//static/style.css' but you need this: 'style.css' ;) ?

MEDIA_URL = '/media/'

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

STATIC_URL = '/static/'

STATIC_ROOT = os.path.join(BASE_DIR, "static/")

urlpatterns = [your urls here] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

You can create in your project folder settings then in them create settings files like names: local.py

from my_project.settings import *
DEBUG = True
ALLOWED_HOSTS = []
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static"),
]
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

this run in VM like: python manage.py runserver --settings settings.local

remember in urls add:

if settings.DEBUG == True:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
    urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

web.py

from my_project.settings import *
DEBUG = False
ALLOWED_HOSTS = ["www.side.com", "side.com"]
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

and then in gunicorn import only web.py file project to read in nginx

this run in VPS server.

Related