我正在尝试在 heroku 上部署我的 django 应用程序。所有静态文件均由其提供服务whitenoise
并成功迁移。但是如何让我上传的媒体文件ImageField
在制作过程中显示。
我的settings.py
STATIC_URL = '/static/'
STATIC_ROOT = 'C:/Users/Sak/mpro/feat/static/'
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
wsgi.py
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mpro.settings")
application = get_wsgi_application()
try:
from django.core.wsgi import get_wsgi_application
from whitenoise.django import DjangoWhiteNoise
application = get_wsgi_application()
application = DjangoWhiteNoise(application)
from dj_static import Cling
application = Cling(get_wsgi_application())
except:
pass
urls.py
urlpatterns = [
url(r'^', include('feat.urls', namespace="feat")),
url(r'^admin/', include(admin.site.urls)),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
我所有的媒体文件都上传到base_dir/media/media
,当whitenoise
收集静态文件时它只收集文件STATIC_ROOT
,所以我如何部署我的媒体文件。当我运行时,heroku run ls
我可以看到文件夹媒体。