How to send a video mp4 file as a response in django? I don't want to embed in a video or object tags of html, but want to send the mp4 itself. Can anyone please help with this issue?
相关问题
- Django __str__ returned non-string (type NoneType)
- Django & Amazon SES SMTP. Cannot send email
- Django check user group permissions
- Django restrict pages to certain users
- UnicodeEncodeError with attach_file on EmailMessag
相关文章
- netcore3中,在OnResultExecuted方法中,怎么读取Response内容
- How to create a MediaClip from RenderTargetBitmap
- Profiling Django with PyCharm
- Why doesn't Django enforce my unique_together
- MultiValueDictKeyError in Django admin
- Django/Heroku: FATAL: too many connections for rol
- Safari blocks play() on video despite being called
- Django is sooo slow? errno 32 broken pipe? dcramer
Generally you don't want to do this; it's better to redirect to a non-Django server to serve static files, with e.g.
django.shortcuts.redirect
-- it'll be faster, more memory-efficient, and probably more secure. But of course sometimes that's not convenient. This should work:The
FileWrapper
(docs) is used so that too much data isn't sent at once, since Python file objects iterate a line at a time, and\n
characters presumably aren't especially common in mp4s. (Sending too much means that the webserver can't send the file as it's read off the hard drive but instead has to wait for long awkwardly-spaced increments.)Note that although I don't see this noted in the documentation anywhere, the file does get closed when it's done with.