【发布时间】:2021-10-28 03:15:11
【问题描述】:
我的静态文件夹中有 excel 文件,我从中读取以获取一些数据,但是当我部署我的项目时这些文件不存在
这些是我配置静态文件的设置
STATIC_URL = '/static/'
STATIC_ROOT = BASE_DIR / 'staticfiles'
STATICFILES_DIRS = [
BASE_DIR / 'static'
]
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
这就是我对他们的看法
from django.conf import settings
from django.templatetags.static import static
from django.contrib.staticfiles.storage import staticfiles_storage
from django.contrib.staticfiles.finders import find
def get_static(path):
if settings.DEBUG:
return find(path)
else:
return static(path)
def sport_news(request):
path = 'excel\sport_update.xlsx'
excel_data = excel(get_static(path))
return render(request, 'news/news.html', {"excel_data":excel_data, 'type':'Sport News'})
【问题讨论】:
标签: django heroku django-views django-staticfiles django-settings