From ad3c25bac043e9d14ce8ffe1b03ae6d0e92b3b0e Mon Sep 17 00:00:00 2001 From: Michael Merickel Date: Sat, 11 Feb 2012 13:52:20 -0600 Subject: Updated the scripting example for more url control. --- docs/narr/commandline.rst | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'docs') diff --git a/docs/narr/commandline.rst b/docs/narr/commandline.rst index a1fcf12f5..95927cfca 100644 --- a/docs/narr/commandline.rst +++ b/docs/narr/commandline.rst @@ -606,19 +606,21 @@ Assuming that you have a route configured in your application like so: config.add_route('verify', '/verify/{code}') You need to inform the Pyramid environment that the WSGI application is -handling requests from a certain base. For example, we want to mount our -application at `example.com/prefix` and the generated URLs should use HTTPS. -This can be done by mutating the request object: +handling requests from a certain base. For example, we want to simulate +mounting our application at `https://example.com/prefix`, to ensure that +the generated URLs are correct for our deployment. This can be done by +either mutating the resulting request object, or more simply by constructing +the desired request and passing it into :func:`~pyramid.paster.bootstrap`: .. code-block:: python from pyramid.paster import bootstrap - env = bootstrap('/path/to/my/development.ini#another') - env['request'].host = 'example.com' - env['request'].scheme = 'https' - env['request'].script_name = '/prefix' + from pyramid.request import Request + + request = Request.blank('/', base_url='https://example.com/prefix') + env = bootstrap('/path/to/my/development.ini#another', request=request) print env['request'].application_url - # will print 'https://example.com/prefix/another/url' + # will print 'https://example.com/prefix' Now you can readily use Pyramid's APIs for generating URLs: @@ -630,8 +632,8 @@ Now you can readily use Pyramid's APIs for generating URLs: Cleanup ~~~~~~~ -When your scripting logic finishes, it's good manners (but not required) to -call the ``closer`` callback: +When your scripting logic finishes, it's good manners to call the ``closer`` +callback: .. code-block:: python -- cgit v1.2.3