認証されたユーザーに提供する必要がある画像、ビデオなどの静的ファイル (アプリケーションを介してアップロードされる) のセットがあります (つまり、Cookie はセッションで認証済みとして登録されます)。
これらのファイルは別個のものであり、css、javaacript などの他のメディア静的ファイルとはまったく関係ありません。
認証が必要な静的ファイルがかなり大きいことを考えると、それらを提供する最も効率的な方法は何だろうと思っていました (ところで、私は wsgi を使用しています)。
現在、私はこれを持っています:
def return_large_file(request, p_filename):
"""
Send a file through Django without loading the whole file into
memory at once. The FileWrapper will turn the file object into an
iterator for chunks of 8KB.
"""
if not os.path.exists(p_filename):
raise Exception('File %s does not exist!')
try:
_content_type = mimetypes.guess_type(p_filename)
except:
_content_type = 'application/octet-stream'
wrapper = FileWrapper(file(p_filename))
response = HttpResponse(wrapper, content_type=_content_type)
response['Content-Length'] = os.path.getsize(p_filename)
return response