Flask Server

pip3 install flask markdown jinja2 pygments

from flask import Flask
from flask import send_file, send_from_directory, render_template_string
from glob import glob
import sys
import markdown
import jinja2
from templates import *

ROOT ="/home/dab/md2web/"
extensions = ['extra', 'smarty', 'codehilite']

app = Flask(__name__)
app.config["DOWNLOAD"] = ROOT + "files"

@app.route('/')
@app.route('/<path:filename>/')
def test(filename=None):

    if filename == None:
       filename = "."

    if (filename.endswith('.png') or filename.endswith('.jpg')):
       print ( filename)
       image = send_from_directory(ROOT, filename)
       print (image)
       return  image

    doc=""
    style = render_template_string(TEMPLATE4)
    files = glob (filename + "/*.md")
    files.sort(key=lambda f: int(''.join(filter(str.isdigit, f))))
    files.reverse()
    for page in files:
       with open(page, "r", encoding="utf-8", errors="ignore") as f:
         md = f.read()
         html = markdown.markdown(md, extensions=extensions)
         doc = doc + jinja2.Template(TEMPLATE2).render(content=html)
         f.close()

    data = style + doc
    return data



@app.route('/files/<filename>')
def send_file(filename):
    return send_from_directory(app.config["DOWNLOAD"], filename=filename)


application = app

Start

pip3 install uwsgi

uwsgi –wsgi-file o21.py –http :5000

Helpful links https://pythonise.com/series/learning-flask/rendering-html-files-with-flask https://www.fullstackpython.com/flask-templating-render-template-examples.html https://www.digitalocean.com/community/tutorials/how-to-make-a-web-application-using-flask-in-python-3-de https://flask.palletsprojects.com/en/1.1.x/quickstart/ https://hackersandslackers.com/flask-routes/ https://pythonise.com/series/learning-flask/sending-files-with-flask https://stackoverflow.com/questions/33241050/trailing-slash-triggers-404-in-flask-path-rule https://stackoverflow.com/questions/15117416/capture-arbitrary-path-in-flask-route https://sodocumentation.net/flask/topic/4637/deploying-flask-application-using-uwsgi-web-server-with-nginx https://uwsgi-docs.readthedocs.io/en/latest/WSGIquickstart.html