如何在heroku服务器上加载静态文件? [英] How to load static files on heroku server?
问题描述
我已经在heroku上成功部署了django项目,但是由于静态文件,我的项目看起来不像本地服务器上的样子.我正在使用django 3.1.4.还有版本控制方面的问题.
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.
此处显示的是本地内容:
这是服务器上的外观:
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
推荐答案
我将在下面显示我的设置代码.
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"),
]
我的看法是,我想我们不能在 STATIC_ROOT
和 STATICFILES_DIRS
处使用/
,因为这是除法运算.请尝试使用 +
或 concat
之类的东西,或者以我的方式使用 os.path.join()
.
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.
这篇关于如何在heroku服务器上加载静态文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!