我有这个配置
settings.py
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'client/templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
#Some dependencies
'django.template.context_processors.media'
],
},
},
]
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles')
STATIC_URL = '/static/'
#STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'
# Extra places for collectstatic to find static files.
STATICFILES_DIRS = (
os.path.join(PROJECT_ROOT, 'static'),
)
在我的 urls.py
中from django.conf.urls import url
from . import views
from django.conf import settings
from django.conf.urls.static import static
app_name = 'client'
urlpatterns = [
url(r'^$', views.index, name='index'),
#some others urls
]
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
我的媒体上传到我的根项目中的/media/
目录中,但是,当我尝试在浏览器中查看这些资源时,不会显示并返回404 error
。
我的配置有什么问题?
答案 0 :(得分:0)
存在权限问题。尝试:
sudo chmod -R a+rw media