Serving Media

Created on Dec. 1, 2012, 8:10 p.m. by Hevok & updated by Hevok on May 2, 2013, 5:26 p.m.

Apache2 server with xsend file enables to serve files from the file-system:

import os

from django.http import HttpResponse
from django.contrib.admin.views.decorators import staff_member_required

def media_xsendfile(request, path, document_root):
    response = HttpResponse()
    response['Content-Disposition'] = 'attachment'
    response['X-Sendfile'] = (os.path.join(document_root, path)).encode('urf-8')
    return response
# http.conf
XSendFile on
XSendFilePath /path/to/files

Tags: files, rest, django
Categories: Tutorial, reST
Parent: Web Framework

Update entry (Admin) | See changes

Comment on This Data Unit