该项目在开发中运行良好,但是当我将其推送到heroku应用程序时,媒体没有显示,这是我的代码 settings.py
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
os.path.join(BASE_DIR, "media"),
]
MEDIA_URL = '/media/'
STATIC_URL = '/static/'
MEDIA_ROOT = (
os.path.join(BASE_DIR, 'media/')
)
STATIC_ROOT = os.path.join(BASE_DIR, 'static_root')
urls.py
from django.contrib import admin
from django.urls import path
from rashed import views
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.index, name="index"),
path('form', views.Createview.as_view(), name="form")
]
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL,
document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL,
document_root=settings.MEDIA_ROOT)