32. ADVANCED CONFIGURATION
1 |
from wsgiref.simple_server import make_server |
2 |
from pyramid.config import Configurator |
3 |
from pyramid.response import Response |
4 |
|
5 |
def hello_world(request): |
6return Response(’Hello world!’)
7
8 def goodbye_world(request):
9return Response(’Goodbye world!’)
10
11if __name__ == ’__main__’:
12config = Configurator()
13
14 config.add_view(hello_world, name=’hello’)
15
16# conflicting view configuration
17config.add_view(goodbye_world, name=’hello’)
18
19app = config.make_wsgi_app()
20server = make_server(’0.0.0.0’, 8080, app)
21server.serve_forever()
The application now has two conflicting view configuration statements. When we try to start it again, it won’t start. Instead, we’ll receive a traceback that ends something like this:
1 |
Traceback (most recent call last): |
2 |
File "app.py", line 12, in <module> |
3app = config.make_wsgi_app()
4File "pyramid/config.py", line 839, in make_wsgi_app
5self.commit()
6File "pyramid/pyramid/config.py", line 473, in commit
7 self._ctx.execute_actions()
8... more code ...
9 pyramid.exceptions.ConfigurationConflictError:
10Conflicting configuration actions
11For: (’view’, None, ’’, None, <InterfaceClass pyramid.interfaces.IView>,
12None, None, None, None, None, False, None, None, None)
13Line 14 of file app.py in <module>: ’config.add_view(hello_world)’
14Line 17 of file app.py in <module>: ’config.add_view(goodbye_world)’
This traceback is trying to tell us:
• We’ve got conflicting information for a set of view configuration statements (The For: line).