37.6. DEFINING VIEWS
1.Add a declaration which maps the pattern / (signifying the root URL) to the route named view_wiki. It maps to our view_wiki view callable by virtue of the @view_config attached to the view_wiki view function indicating route_name=’view_wiki’.
2.Add a declaration which maps the pattern /{pagename} to the route named view_page.
This is the regular view for a page. It maps to our view_page view callable by virtue of the @view_config attached to the view_page view function indicating route_name=’view_page’.
3.Add a declaration which maps the pattern /add_page/{pagename} to the route named add_page. This is the add view for a new page. It maps to our add_page view callable by virtue of the @view_config attached to the add_page view function indicating route_name=’add_page’.
4.Add a declaration which maps the pattern /{pagename}/edit_page to the route named edit_page. This is the edit view for a page. It maps to our edit_page view callable by virtue of the @view_config attached to the edit_page view function indicating route_name=’edit_page’.
As a result of our edits, the __init__.py file should look something like:
1 |
from pyramid.config |
import Configurator |
2 |
from |
sqlalchemy import engine_from_config |
3 |
|
|
|
4 |
from |
.models import |
DBSession |
5
6 def main(global_config, **settings):
7""" This function returns a Pyramid WSGI application.
8"""
9engine = engine_from_config(settings, ’sqlalchemy.’)
10DBSession.configure(bind=engine)
11config = Configurator(settings=settings)
12config.add_static_view(’static’, ’static’, cache_max_age=3600)
13config.add_route(’view_wiki’, ’/’)
14config.add_route(’view_page’, ’/{pagename}’)
15config.add_route(’add_page’, ’/add_page/{pagename}’)
16config.add_route(’edit_page’, ’/{pagename}/edit_page’)
17config.scan()
18return config.make_wsgi_app()
(The highlighted lines are the ones that need to be added or edited.)