Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8897603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:23:18+00:00 2026-06-15T00:23:18+00:00

By default Flask uses template files stored in the "templates" directory: /flaskapp /application.py /templates

  • 0

By default Flask uses template files stored in the "templates" directory:

/flaskapp
    /application.py
    /templates
        /hello.html

Is there any way to dynamically choose a template directory according to the logged-in user?

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 the logged-in user and the name of the template activated by the user, is it possible to dynamically select the directory to load template files from?

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 their website.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T00:23:20+00:00Added an answer on June 15, 2026 at 12:23 am

    There is also the possibility to overwrite Jinja loader and set the paths where Jinja will look for the templates. Like:

    my_loader = jinja2.ChoiceLoader([
            app.jinja_loader,
            jinja2.FileSystemLoader(['/flaskapp/userdata', 
                                     '/flaskapp/templates']),
        ])
    app.jinja_loader = my_loader
    

    Directories are arranged in the order where Jinja needs to first start looking for it. Then from the view you can render user specific template like this:

    render_template('%s/template1/hello.html' % username)
    

    where username you can dinamically change in the view. Of course you can also there choose which template (1 or 2) to render. But basically what you really miss is this custom Jinja loader with the custom paths.

    Hope that helped or gave the ideas 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Default JVM uses maximum 1.5 GB RAM/JVM Java application. But my Server have 8
Looking at the default Hello world script on Flask's website: from flask import Flask
PHP uses magic quotes by default but has gotten a lot of flak for
By default, the ordered list looks like this: There are some spacing on the
By default pip installs editable packages into src subdirectory of the directory where Python
My Flex 3 application uses a custom cursor and has to show a customized
I'm trying to issue a POST request within a Jinja template in Flask .
I'm writing an application with Flask and I'd like to generate different code for
I'm having trouble getting a simple Hello World app to work using Flask, MongoDB,
I'm desperately trying to solve this one. I have a bunch of files stored

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.