3👍
✅
You need to tell it to serve your media files. In your urls.py
:
from django.conf import settings
if settings.DEBUG == False:
urlpatterns += patterns('',
url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {
'document_root': settings.MEDIA_ROOT,
}),
url(r'^static/(?P<path>.*)$', 'django.views.static.serve', {
'document_root': settings.STATIC_ROOT,
}),
)
0👍
Write:
import re
from urllib.parse import urlsplit
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.urls import re_path
from django.views.static import serve
def static(prefix, view=serve, **kwargs):
return [
re_path(r'^%s(?P<path>.*)$' % re.escape(prefix.lstrip('/')), view, kwargs=kwargs),
]
Then in urls.py
:
urlpatterns = [
path('admin/', admin.site.urls),
...
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
- [Django]-NGINX 502 bad gateway gunicorn timeout
- [Django]-Celery scheduled tasks with expiration time for each task instance?
- [Django]-How to return custom JSON response in UpdateAPIView?
- [Django]-Django addConstraints raises a TypeError on Postgres
- [Django]-Extending the user model with Django-Registration
Source:stackexchange.com