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__)

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

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__':

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?

1 Like

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.

1 Like