3
votes
This is project structure
├── run.py
└── test_blueprint
    ├── __init__.py
    ├── __init__.pyc
    ├── mainsite
    │   ├── controllers
    │   │   ├── controllers.py
    │   │   ├── controllers.pyc
    │   │   ├── __init__.py
    │   │   └── __init__.pyc
    │   ├── __init__.py
    │   ├── __init__.pyc
    │   ├── static
    │   │   ├── css
    │   │   │   ├── bootstrap.min.css
    │   │   │   └── signin.css
    │   │   └── js
    │   └── templates
    │       └── mainsite
    │           └── homepage.html
    ├── static
    │   ├── css
    │   │   ├── bootstrap.min.css
    │   │   └── signin.css
    │   └── js
    ├── templates
    │   └── mainsite
    │       └── index1.html
    └── usermanagement
        ├── controllers
        │   ├── controllers.py
        │   ├── controllers.pyc
        │   ├── __init__.py
        │   └── __init__.pyc
        ├── __init__.py
        ├── __init__.pyc
        ├── static
        └── templates

Here I have two blue prints mainsite and usermanagement. I have registered this in file init.py under test_blueprint folder which is main folder (one below the blueprint_project folder which has run.py)

__init__ file under test_blueprint


    from flask import Flask
    app=Flask(__name__)
    from test_blueprint.mainsite.controllers.controllers import mod 
    from test_blueprint.usermanagement.controllers.controllers import mod 

    app.register_blueprint(mainsite.controllers.controllers.mod,url_prefix="/"  )
    app.register_blueprint(usermanagement.controllers.controllers.mod,url_prefix="/usermanagement")

Now post that I have under each blueprint folder I have created init.py in which I have defined Blueprints along with template folder. However, I does not take template from there. It keeps on throwing error template not found. So, I have created template folder under test_blueprint folder. It perfectly picks index.html from templates/mainsite folder. Also, if i provided /home/user/flaskenv/blueprint_project/.... templates folder which is absolute path for my template under blueprint folder. it works fine.

Not sure if it's bug is flask. I saw video on youtube and expected my flask project to behave same. Unfortunately it didn't

https://www.youtube.com/watch?v=erz8IxI8or8&t=238s

This is my controller.py/views.py file looks like for mainsite


    from flask import Blueprint,render_template,url_for


    mod=Blueprint('mainsite',__name__,static_folder='static',template_folder='templates')
    @mod.route("/")
    def home():
        return render_template('mainsite/homepage.html')


Now if I used os.path.abspath to locate template folder under blueprint folder, than passed that path as variable to template_folder and it works fine.

Now my expectation as per flask documentation is that just mentioning template_folder='templates' should automatically locate templates under blueprint folder or it entirely defeats the purpose.

Any help would apprecated

1

1 Answers

0
votes

I solved by renaming the html file by unique name