Hugo + Flask for a website

I’m doing a sample ecommerce site for a web dev course I am in.
I got into JAMStack recently so I decided to use it as a way to build my site, but I am not sure how to use the backend.
I know I can use Flask and Hugo servers separately and have an nginx reverse proxy but I want to serve hugo directly through flask.

from flask import Flask, send_from_directory

app = Flask(__name__)

@app.route('/')
def index():
    return send_from_directory('static/public', 'index.html')

@app.route('/<path:filename>')
def static_files(filename):
    # Prevent adding "index.html" to paths of HTML, CSS, JS, and image files
    if not filename.endswith(('.html', '.css', '.js','svg', '.jpg', '.png', '.gif')):
        filename += "/index.html"
    return send_from_directory('static/public', filename)

if __name__ == '__main__':
    app.run(debug=True)

This is my starting code, does anyone have any advice on whether this is a good idea or should I use reverse proxy or any other method?

Not sure to understand what you are trying to do, but Hugo have no backend, you can’t use hugo serve on production. After building your website with Hugo you have just to put the files from public to a web environment, so you don’t need Flask or another dynamic framework to serve it.

Flask actually uses different language rules to render its pages
that it might be counterintuitive to mix hugo and flask. That being said this is something that I would like to try as well for the reason of surpassing the static sites that I’ve created using hugo.

On this tutorial they talk about using flask language in the code:

<ul class="menu">
            <li><a href="{{ url_for('home') }}">Home</a></li>
            <li><a href="{{ url_for('about') }}">About</a></li>
          </ul>

but this is amount identical to the shortcode that hugo uses, which means that you would only be able to attach flask applications to hugo sites after you have build the site in /public/ and transferred it to your cpanel.

This is where I am at, however before doing that I would like to build the static site using flask to test the application, in my case a subscription form, but the differences in how flask serves sites means that almost all the convenience of hugo gets destroyed in the process.