Categories
Python Answers

How to dynamically select template directory to be used in Python Flask?

Spread the love

Sometimes, we want to dynamically select template directory to be used in Python Flask.

In this article, we’ll look at how to dynamically select template directory to be used in Python Flask.

How to dynamically select template directory to be used in Python Flask?

To dynamically select template directory to be used in Python Flask, we set the template_folder argument when we create our Flask instance.

For instance, we write

Flask(__name__, template_folder="templates")

to create the Flask instance with the template_folder argument set to 'templates'.

Then the templates will be read from the templates directory.

Conclusion

To dynamically select template directory to be used in Python Flask, we set the template_folder argument when we create our Flask instance.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *