Serving files uploaded by a user during development.¶
During development, you can serve user-uploaded media files from MEDIA_ROOT using the
django.contrib.staticfiles.views.serve()
view.This is not suitable for production use! For some common deployment strategies, see Deploying static files.
For example, if your MEDIA_URL is defined as /media/, you can do this by adding the following snippet to your urls.py:
from django.conf import settings from django.conf.urls.static import static urlpatterns = [ # ... the rest of your URLconf goes here ... ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
这是否意味着在生产环境中不应使用+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
,还是应该使用?
我的理解是,您不应使用django.contrib.staticfiles.views.serve()
,但我不确定是否相同。