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

5.8. THE MYPROJECT PROJECT

MyProject/

|-- CHANGES.txt

|-- development.ini |-- MANIFEST.in

|-- myproject

||-- __init__.py

||-- static

|| |-- favicon.ico

|| |-- logo.png

|| ‘-- pylons.css

||-- templates

|| ‘-- mytemplate.pt

|

|--

tests.py

|

‘--

views.py

|-- production.ini |-- README.txt

|-- setup.cfg ‘-- setup.py

5.8 The MyProject Project

The MyProject project directory is the distribution and deployment wrapper for your application. It contains both the myproject package representing your application as well as files used to describe, run, and test your application.

1.CHANGES.txt describes the changes you’ve made to the application. It is conventionally written in ReStructuredText format.

2.README.txt describes the application in general. It is conventionally written in ReStructuredText format.

3.development.ini is a PasteDeploy configuration file that can be used to execute your application during development.

4.production.ini is a PasteDeploy configuration file that can be used to execute your application in a production configuration.

5.setup.cfg is a setuptools configuration file used by setup.py.

6.MANIFEST.in is a distutils “manifest” file, naming which files should be included in a source distribution of the package when python setup.py sdist is run.

7.setup.py is the file you’ll use to test and distribute your application. It is a standard setuptools setup.py file.

47

5. CREATING A PYRAMID PROJECT

5.8.1 development.ini

The development.ini file is a PasteDeploy configuration file. Its purpose is to specify an application to run when you invoke pserve, as well as the deployment settings provided to that application.

The generated development.ini file looks like so:

1

[app:main]

 

2

use = egg:MyProject

 

3

 

 

4

pyramid.reload_templates

= true

5

pyramid.debug_authorization = false

6

pyramid.debug_notfound =

false

7

pyramid.debug_routematch

= false

8

pyramid.default_locale_name = en

9

pyramid.includes =

 

10

pyramid_debugtoolbar

 

11

 

 

12[server:main]

13use = egg:waitress#main

14host = 0.0.0.0

15port = 6543

16

17 # Begin logging configuration

18

19[loggers]

20keys = root, myproject

21

22[handlers]

23keys = console

24

25[formatters]

26keys = generic

27

28[logger_root]

29level = INFO

30handlers = console

31

32[logger_myproject]

33level = DEBUG

34handlers =

35qualname = myproject

36

37[handler_console]

38class = StreamHandler

39args = (sys.stderr,)

48

5.8. THE MYPROJECT PROJECT

40level = NOTSET

41formatter = generic

42

43[formatter_generic]

44format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s

45

46 # End logging configuration

This file contains several sections including [app:main], [server:main] and several other sections related to logging configuration.

The [app:main] section represents configuration for your Pyramid application. The use setting is the only setting required to be present in the [app:main] section. Its default value, egg:MyProject, indicates that our MyProject project contains the application that should be served. Other settings added to this section are passed as keyword arguments to the function named main in our package’s __init__.py module. You can provide startup-time configuration parameters to your application by adding more settings to this section.

latex-note.png

See Entry Points and PasteDeploy .ini Files for more information about the meaning of the use = egg:MyProject value in this section.

The pyramid.reload_templates setting in the [app:main] section is a Pyramid -specific setting which is passed into the framework. If it exists, and its value is true, Chameleon and Mako template changes will not require an application restart to be detected. See Automatically Reloading Templates for more information.

latex-warning.png

The pyramid.reload_templates option should be turned off for production applications, as template rendering is slowed when it is turned on.

The pyramid.includes setting in the [app:main] section tells Pyramid to “include” configuration from another package. In this case, the line pyramid.includes = pyramid_debugtoolbar

49

5. CREATING A PYRAMID PROJECT

tells Pyramid to include configuration from the pyramid_debugtoolbar package. This turns on a debugging panel in development mode which will be shown on the right hand side of the screen. Including the debug toolbar will also make it possible to interactively debug exceptions when an error occurs.

Various other settings may exist in this section having to do with debugging or influencing runtime behavior of a Pyramid application. See Environment Variables and .ini File Settings for more information about these settings.

The name main in [app:main] signifies that this is the default application run by pserve when it is invoked against this configuration file. The name main is a convention used by PasteDeploy signifying that it is the default application.

The [server:main] section of the configuration file configures a WSGI server which listens on TCP port 6543. It is configured to listen on all interfaces (0.0.0.0). This means that any remote system which has TCP access to your system can see your Pyramid application.

The sections that live between the markers # Begin logging configuration and # End logging configuration represent Python’s standard library logging module configuration for your application. The sections between these two markers are passed to the logging module’s config file configuration engine when the pserve or pshell commands are executed. The default configuration sends application logging output to the standard error output of your terminal. For more information about logging configuration, see Logging.

See the PasteDeploy documentation for more information about other types of things you can put into this

.ini file, such as other applications, middleware and alternate WSGI server implementations.

5.8.2 production.ini

The production.ini file is a PasteDeploy configuration file with a purpose much like that of development.ini. However, it disables the debug toolbar, and filters all log messages except those above the WARN level. It also turns off template development options such that templates are not automatically reloaded when changed, and turns off all debugging options. This file is appropriate to use instead of development.ini when you put your application into production.

It’s important to use production.ini (and not development.ini) to benchmark your application and put it into production. development.ini configures your system with a debug toolbar that helps development, but the inclusion of this toolbar slows down page rendering times by over an order of magnitude. The debug toolbar is also a potential security risk if you have it configured incorrectly.

50

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