How to load static files on heroku server?

拈花ヽ惹草 提交于 2021-01-25 07:10:08

问题


I have successfully deployed my django project on heroku but my project is not looking as it looks on local server due to static files i guess. I am using django 3.1.4. And having issues with version control.

here what its look on local :

here what its look on server :

settings.py:

STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'


STATIC_ROOT = BASE_DIR / 'staticfiles'

STATIC_URL = '/static/'

STATICFILES_DIRS = [
    BASE_DIR / "static",
    '/var/www/static/',
]

if more code is require then tell me i will update my question with that information thank you


回答1:


I would show my setup code below.

SITE_ROOT = os.path.dirname(BASE_DIR)
STATIC_ROOT = os.path.join(SITE_ROOT, "staticfiles")
STATIC_URL = "/static/"

# Extra places for collectstatic to find static files.
STATICFILES_DIRS = [
    os.path.join(SITE_ROOT, "static"),
]

My opinion is I guess we can't use / at STATIC_ROOT and STATICFILES_DIRS because it's the divide operation. please try to use something like + or concat or in my way which use os.path.join() instead.



来源:https://stackoverflow.com/questions/65783856/how-to-load-static-files-on-heroku-server

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