Skip to content
Advertisement

Flask: unable to serve rendered pages from specific directory

I have a bunch of files in a directory that I wish to render and serve to the user, but have been unable to. Going to the path always returns just the 'page_template.htm' and not the rendered file. Here’s my code:

JavaScript

What I wish to do is to grab raw text files from the 'Special_Data' directory and to render them into html files so they look nice, then send them to the user if they click on a link.

The files are in the directory 'Special_Data' and the 'page_template.htm' is in the 'templates' directory.

Where am I going wrong?

Advertisement

Answer

The following example shows you how you can use FlatPages to list, display and offer files for download. The markdown code is rendered beforehand and integrated into the specified or the default template.

JavaScript

templates/contents.html

JavaScript

templates/flatpage.html

JavaScript

pages/Special_Data/ncs1.html

JavaScript

If you want to use a different template for rendering, you can define one within the metadata based on the file name. Add the following below published and a suitable template within the templates folder.

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement