zhanymkanov / fastapi-best-practices

FastAPI Best Practices and Conventions we used at our startup
9.4k stars 701 forks source link

Any suggestion on where to create the Jinja2Templates object? #54

Closed carlosnatalino closed 2 months ago

carlosnatalino commented 2 months ago

Hi,

I am starting a new project that will use FastAPI, but most of the routes will return HTML rendered through Jinja2. My plan is to have specific folders for each module of my system. What do you suggest as the file/place where to create the Jinja2Templates object so that I can import it in each one of the modules?

Thanks in advance.

zhanymkanov commented 2 months ago

Hey,

You can put in any module you want (e.g. jinja.py, templates.py) and then init that object in main.py before starting the server. Or you can simply create and init it in main.py, since most of your routes will return HTML.

carlosnatalino commented 2 months ago

@zhanymkanov thanks for the suggestion!