Cannot access video file in MEDIA folder
It's strange here. I am creating a basic application that allows users to download videos and then play them. Just. When a user uploads a file, a link to it is stored in mysql, and the file itself is stored in the file system at web_app / media / videos /.
In settings.py:
STATIC_URL = '/static/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'web_app/media')
MEDIA_URL = '/media/'
My corresponding directory structure:
project/web_app/static/
project/web_app/media/
The download works fine and then both the db write and video files are as expected. The problem is that I cannot access the file using video link. Right now, in my view template, I have the following:
{% block body %}
<div><video src="{{ MEDIA_URL }}{{ path_to_video }}" width=640 height=360 controls></video></div>
<div><video src="/static/videos/2015/05/18/vid1.mp4" width=640 height=360 controls></video></div>
{% endblock body %}
The first div is obviously what I'm trying to use and the second is for debugging - you'll see why in a second. This template results in the following html:
<div><video src="/media/videos/2015/05/18/vid1.mp4" width=640 height=360 controls></video></div>
<div><video src="/static/videos/2015/05/18/vid1.mp4" width=640 height=360 controls></video></div>
Again, as expected. Here's the thing: the first link doesn't work, saying it can't find the file. But if I manually copy "videos / 2015 / etc ..." to the / static folder, the second link works as expected. What's going on here? Are there any permission issues in the media folder?
I don't know if this matters, but this is on Windows ... Thanks.
source to share
This is a problem someone is having with Django development server ... This is what I have in urls.py
:
from django.conf import settings
from django.conf.urls.static import static
# ...
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) # pragma: nocover
In live / production, this should be handled by the web server.
(comment #pragma
for the package coverage
.)
The above is covered in the Django documentation : Uploading files uploaded by the user during development . See Also Serving Static Files During Development .
source to share