Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
pyramid.pdf
Скачиваний:
10
Добавлен:
24.03.2015
Размер:
3.82 Mб
Скачать

20.COMMAND-LINE PYRAMID

>>>request.route_url(’home’) ’https://www.example.com/’

20.2.2 IPython or bpython

If you have IPython or bpython or both installed in the interpreter you use to invoke the pshell command, pshell will autodiscover them and use the first respectively found in this order : IPython, bpython, standard Python interpreter. However you could specifically invoke one of your choice with the -p choice or --python-shell choice option.

[chrism@vitaminf shellenv]$ ../bin/pshell -p ipython | bpython | python \ development.ini#MyProject

20.3 Displaying All Application Routes

You can use the proutes command in a terminal window to print a summary of routes related to your application. Much like the pshell command (see The Interactive Shell), the proutes command accepts one argument with the format config_file#section_name. The config_file is the path to your application’s .ini file, and section_name is the app section name inside the .ini file which points to your application. By default, the section_name is main and can be omitted.

For example:

1

[chrism@thinko MyProject]$ ../bin/proutes development.ini

2

Name

Pattern

View

3

----

-------

----

4

home

/

<function my_view>

5

home2

/

<function my_view>

6

another

/another

None

7

static/

static/*subpath

<static_view object>

8

catchall

/*subpath

<function static_view>

proutes generates a table. The table has three columns: a Name column, a Pattern column, and a View column. The items listed in the Name column are route names, the items listed in the Pattern column are route patterns, and the items listed in the View column are representations of the view callable that will be invoked when a request matches the associated route pattern. The view column may show None if no associated view callable could be found. If no routes are configured within your application, nothing will be printed to the console when proutes is executed.

216

20.4. DISPLAYING “TWEENS”

20.4 Displaying “Tweens”

A tween is a bit of code that sits between the main Pyramid application request handler and the WSGI application which calls it. A user can get a representation of both the implicit tween ordering (the ordering specified by calls to pyramid.config.Configurator.add_tween()) and the explicit tween ordering (specified by the pyramid.tweens configuration setting) orderings using the ptweens command. Tween factories will show up represented by their standard Python dotted name in the ptweens output.

For example, here’s the pwteens command run against a system configured without any explicit tweens:

1

[chrism@thinko pyramid]$ myenv/bin/ptweens development.ini

 

2

"pyramid.tweens" config value NOT set (implicitly ordered tweens used)

3

 

 

 

4

Implicit Tween Chain

 

5

 

 

 

6

Position

Name

Alias

7

--------

----

-----

8

-

-

INGRESS

9

0

pyramid_debugtoolbar.toolbar.toolbar_tween_factory

pdbt

10

1

pyramid.tweens.excview_tween_factory

excview

11

-

-

MAIN

 

 

 

 

Here’s the pwteens command run against a system configured with explicit tweens defined in its development.ini file:

1

[chrism@thinko pyramid]$ ptweens development.ini

 

2

"pyramid.tweens" config value set (explicitly ordered tweens used)

3

 

 

 

4

Explicit Tween Chain (used)

 

5

 

 

 

6

Position

Name

 

7

--------

----

 

8

-

INGRESS

 

9

0

starter.tween_factory2

 

10

1

starter.tween_factory1

 

11

2

pyramid.tweens.excview_tween_factory

 

12

-

MAIN

 

13

 

 

 

14

Implicit Tween Chain (not used)

 

15

 

 

 

16

Position

Name

Alias

17

--------

----

-----

18

-

-

INGRESS

217

20. COMMAND-LINE PYRAMID

19

20

21

0

pyramid_debugtoolbar.toolbar.toolbar_tween_factory

pdbt

1

pyramid.tweens.excview_tween_factory

excview

-

-

MAIN

 

 

 

Here’s the application configuration section of the development.ini used by the above ptweens command which reports that the explicit tween chain is used:

1

[app:main]

 

2

use = egg:starter

 

3

reload_templates

= true

4

debug_authorization = false

5

debug_notfound =

false

6

debug_routematch

= false

7

debug_templates = true

8

default_locale_name = en

9

pyramid.include = pyramid_debugtoolbar

10

pyramid.tweens =

starter.tween_factory2

11

 

starter.tween_factory1

12

 

pyramid.tweens.excview_tween_factory

 

 

 

See Registering “Tweens” for more information about tweens.

20.5 Invoking a Request

You can use the prequest command-line utility to send a request to your application and see the response body without starting a server.

There are two required arguments to prequest:

The config file/section: follows the format config_file#section_name where config_file is the path to your application’s .ini file and section_name is the app section name inside the .ini file. The section_name is optional, it defaults to main. For example: development.ini.

The path: this should be the non-url-quoted path element of the URL to the resource you’d like to be rendered on the server. For example, /.

For example:

218

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]