Add docstring to readthedocs.core.views.serve._serve_file
@@ -139,6 +139,23 @@ def _serve_401(request, project):
def _serve_file(request, filename, basepath):
+ """
+ Serve media file via Django or NGINX based on ``PYTHON_MEDIA``.
+
+ When using ``PYTHON_MEDIA=True`` (or when ``DEBUG=True``) the file is served
+ by ``django.views.static.serve`` function.
+
+ On the other hand, when ``PYTHON_MEDIA=False`` the file is served by using
+ ``X-Accel-Redirect`` header for NGINX to take care of it and serve the file.
+
+ :param request: Django HTTP request
+ :param filename: path to the filename to be served relative to ``basepath``
+ :param basepath: base path to prepend to the filename
+
+ :returns: Django HTTP response object
+
+ :raises: ``Http404`` on ``UnicodeEncodeError``
+ """
# Serve the file from the proper location
if settings.DEBUG or getattr(settings, 'PYTHON_MEDIA', False):
# Serve from Python
