Menu Close

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

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.

Posted in Python, Python Answers