django-ranged-response

raw JSON →
0.2.0 verified Mon Apr 27 auth: no python

A modified Django FileResponse that adds Content-Range headers for partial content support in file downloads. Version 0.2.0 is the latest, with no recent updates.

pip install django-ranged-response
error AttributeError: 'RangedFileResponse' object has no attribute 'seek'
cause The file-like object passed must support seek operations.
fix
Open the file in binary read mode with 'rb' and ensure it is a real file object, not a BytesIO without seek.
error ImportError: No module named 'ranged_response'
cause Attempting to import with hyphens or wrong package name.
fix
Install via 'pip install django-ranged-response' and import as 'from ranged_response import RangedFileResponse'.
gotcha The library is named 'django-ranged-response' on PyPI, but import uses 'ranged_response' (underscore, not hyphen).
fix Use 'from ranged_response import RangedFileResponse'.
deprecated The library has not been updated since 2019 and may not support newer Django versions (e.g., Django 4.x+).
fix Consider using Django's built-in FileResponse with custom range headers or other maintained libraries.
gotcha Requires passing the HttpRequest object as the first argument to RangedFileResponse. Forgetting this causes incorrect range handling.
fix Always pass 'request' as first argument: RangedFileResponse(request, file_handle).

Basic usage in a Django view returning a file with range support.

from django.http import FileResponse
from ranged_response import RangedFileResponse

class MyView:
    def get(self, request):
        file_path = '/path/to/file.txt'
        response = RangedFileResponse(request, open(file_path, 'rb'))
        return response