问题
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