summaryrefslogtreecommitdiff
path: root/docs/narr
diff options
context:
space:
mode:
authorChris McDonough <chrism@plope.com>2012-02-22 21:30:15 -0500
committerChris McDonough <chrism@plope.com>2012-02-22 21:30:15 -0500
commitfae09cd18a64efb32150dd0587995ed96cfc9523 (patch)
treef64ce3e285078253554dfc0f2bf1aa8e2c32da76 /docs/narr
parent08f805a360185c648bfeccbbe568a97f0f036a0c (diff)
parent662d6ea96a79cdd9943a9e3c871fe07282ee671c (diff)
downloadpyramid-fae09cd18a64efb32150dd0587995ed96cfc9523.tar.gz
pyramid-fae09cd18a64efb32150dd0587995ed96cfc9523.tar.bz2
pyramid-fae09cd18a64efb32150dd0587995ed96cfc9523.zip
Merge branch '1.3-branch'
Diffstat (limited to 'docs/narr')
-rw-r--r--docs/narr/assets.rst15
1 files changed, 9 insertions, 6 deletions
diff --git a/docs/narr/assets.rst b/docs/narr/assets.rst
index 2cc870619..22b38c929 100644
--- a/docs/narr/assets.rst
+++ b/docs/narr/assets.rst
@@ -370,19 +370,22 @@ do so, do things "by hand". First define the view callable.
:linenos:
import os
- from pyramid.response import Response
+ from pyramid.response import FileResponse
def favicon_view(request):
here = os.path.dirname(__file__)
- icon = open(os.path.join(here, 'static', 'favicon.ico'), 'rb')
- return Response(content_type='image/x-icon', app_iter=icon)
+ icon = os.path.join(here, 'static', 'favicon.ico')
+ return FileResponse(icon, request=request)
The above bit of code within ``favicon_view`` computes "here", which is a
path relative to the Python file in which the function is defined. It then
uses the Python ``open`` function to obtain a file handle to a file within
-"here" named ``static``, and returns a response using the open the file
-handle as the response's ``app_iter``. It makes sure to set the right
-content_type too.
+"here" named ``static``, and returns a :class:`pyramid.response.FileResponse`
+using the file path as the response's ``path`` argument and the request as
+the response's ``request`` argument. :class:`pyramid.response.FileResponse`
+will serve the file as quickly as possible when it's used this way. It makes
+sure to set the right content length and content_type too based on the file
+extension of the file you pass.
You might register such a view via configuration as a view callable that
should be called as the result of a traversal: