Playing Video with Django and html tag

290 views
Skip to first unread message

תמר בביוף

unread,
Apr 21, 2021, 6:45:05 PM4/21/21
to Django users
Hello everyone
 :I try to enable a video tag in HTML like this 
<video width="530" height="440" controls autoplay>
<source src="../static/you.mp4" type="video/mp4"></source>
</video>
:My problem is that the video does not run on Django, and looks like a black 
 Running on html alone it works,  
Does anyone know what the problem is? Is not a video tag enough when using Django?  

Thiago Luiz Parolin

unread,
Apr 21, 2021, 8:12:32 PM4/21/21
to django...@googlegroups.com
try using {% static.. to server your file.

‪Em qua., 21 de abr. de 2021 às 19:44, ‫תמר בביוף‬‎ <tamar...@gmail.com> escreveu:‬
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/db9c1818-3312-45b4-a652-6a2dbc5bb688n%40googlegroups.com.


--
Thiago Luiz Parolin

Benjamin Schollnick

unread,
Apr 21, 2021, 9:57:46 PM4/21/21
to django...@googlegroups.com
What web browser are you using?

I had to work my way around this as well, and it ended up being that I had to use:

RangedFileResponse module.
Name: django-ranged-response
Version: 0.2.0
Summary: Modified Django FileResponse that adds Content-Range headers.
Author: Spindle
License: MIT
Location: /Users/benjamin/venvs/quickbbs/lib/python3.9/site-packages
Requires: django
Required-by: 

And I am using this wrapper, for the download:

def download(request, filename=None):
    """
    Replaces new_download.  
    
    This now takes http://<servername>/downloads/<filename>?UUID=<uuid>
    
    This fakes the browser into displaying the filename as the title of the
    download.  
    
    """
    # Is this from an archive?  If so, get the Page ID.
    d_uuid=request.GET.get("UUID", None)
    if d_uuid == None:
        d_uuid=request.GET.get("uuid", None)
    
    if d_uuid in ["", None]:
        raise Http404

    page = request.GET.get('page', None)
    if page is None:
        download = index_data.objects.filter(uuid=d_uuid,
                                             ignore=False,
                                             delete_pending=False)[0]
    else:
        print ("Attempting to find page %s in archive" % page)

    print("\tDownloading - %s, %s" % (download.fqpndirectory.lower(),
                                      download.name))
                                      
    movie = download.filetype.is_movie
    return respond_as_inline(request,
                                 "%s%s%s" % (
                                     configdata["locations"]["albums_path"],
                                     os.sep,
                                     download.fqpndirectory),
                                 download.name,
                                 ranged=movie)


def respond_as_inline(request, file_path, original_filename, ranged=False):
    filename = os.path.join(file_path, original_filename)
    if os.path.exists(filename):
        mtype, encoding = mimetypes.guess_type(original_filename)
        if mtype is None:
            mtype = 'application/octet-stream'

        with open(filename, 'rb') as fh:
            if ranged:
                response = RangedFileResponse(request, file=open(filename, 'rb'), as_attachment=False, filename=original_filename)
                response["Content-Type"] = mtype
            else:
                response = HttpResponse(fh.read(), content_type=mtype)
                response['Content-Disposition'] = 'inline; filename=%s'% original_filename
        return response    
    else:
        print("File not found")
    raise Http404

For the web side..

                            {% if item.filetype.is_movie %}
 <video class="video-js" data-setup='{}' controls>
  <source src="/download/{{ item.uuid }}" type="video/mp4">
</video>
                            {% endif %}

Hope that helps.  And yes, the python code is intended as a starting place, as it’s very specific to my implementation of a web gallery..
But I’m more than happy to try to help…

- Benjamin


Reply all
Reply to author
Forward
0 new messages