By default flask uses template files stored in "template" directory :
/flaskapp /application.py /templates /hello.html
Is there any way to dynamically choose template directory according to user logged in? This is how I want the directory structure to be :
/flaskapp /application.py /templates (default template goes here) /hello.html /userdata /user1 /template1 hello.html /template2 hello.html /user2 /template1 hello.html /template2 hello.html
Now if I have the username of logged in user and the name of template activated by user, is it possible to dynamically select the directory to load template files? For example,
/userdata/<username>/<activated template name>/
instead of fixed
/templates/
What I am trying to achieve is a wordpress like theme system for my web application where users can upload/select themes for his website.
Template inheritance allows you to build a base “skeleton” template that contains all the common elements of your site and defines blocks that child templates can override.
html template file in a directory called templates inside your flask_app directory. Flask looks for templates in the templates directory, which is called templates , so the name is important. Make sure you're inside the flask_app directory and run the following command to create the templates directory: mkdir templates.
Flask uses the Jinja template library to render templates. In your application, you will use templates to render HTML which will display in the user's browser. In Flask, Jinja is configured to autoescape any data that is rendered in HTML templates.
You can pass the Flask constructor a "template_folder" argument.
Like so...
Flask(__name__, template_folder="wherever")
Here's the documentation: http://flask.pocoo.org/docs/api/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With