What is the proper way to serve multipage applications with templates?

I have been working on a Multipage application where each page uses a separate template. Namely the end of my app.py file looks something like this:

pn.serve({
    "":page1,
    "last_page":page3,
    "content_page":page2,
},static_dirs={'assets': './static/assets','thumbnails':'./static/assets/thumbnails'},
websocket_origin=['*'],port=5506,allow_websocket_origin='localhost:5006')

where each of the page1,page2,page3, functions has a return template.servable() statement at the end of it.

When deploying the application from the command line using ~$ panel serve app.py --address IPADDRESS --allow-websocket-origin=IPADDRESS:5006 I don’t actually get the pages loading when I visit the page IPADDRESS:5006/app. What’s more, when I try any of the other addresses (i.e. IPADDRESS:5006/app.content_page) it simply yields a 404 error.

I am wondering if someone has a better approach?

1 Like

If you ready pn.serve the servable just run as a python program
Look at pipeline module in Python for switching between “pages”

I don’t follow, are you suggesting I should attach .servable() at the end of the pn.serve call?

I meant you are already calling the pn.serve function so all you need to do is call do is run app.py as a python program from the command line

python app.py

Take a look at this example Serving multiple applications — Panel v1.3.8

If you copy and paste that into app.py and then run it from the command line you should be able to see the different pages

If you go the servable route you will have to move many of the options specified programmatically to the command line such static assets directory, etc. See this in the docs Launching a server on the commandline — Panel v1.3.8