In my pyramid app, I have several static html files under tutorial/tutorial/pages/name.html (for example). How can I write a view callable for this? Would this work?
@view_config(renderer='view_page')
def view_page(request):
return {} # no values have to be passed to the template
then in the init.py file
config.add_route('view_page', 'tutorial:pages/{name}.html')
What do I need to put in the def view_page(request) function to call that name.html file specifically and then display its content?
Pyramid’s
static_viewis a view capable of serving files from a directory. The part you really haven’t explained is what the URLs are like for these static pages. For example, if they are all under a common prefix, you could usestatic_view(option 1). If they are not, then you have to create a view per page and serve it up directly (option 2).option 1
url:
static view:
tutorial/pages hierarchy:
add_static_viewis effectively like callingadd_route('foo', '/foo/*subpath'), and it serves up thesubpathrelative totutorial:pages.option 2
Notice the
.makosuffix to invoke the mako renderer. There is no.htmlrenderer by default, but you could make one.