pallets / flask

The Python micro framework for building web applications.
https://flask.palletsprojects.com
BSD 3-Clause "New" or "Revised" License
67.56k stars 16.15k forks source link

blueprint does not render template relative to the blueprint. #3747

Closed bokunodev closed 4 years ago

bokunodev commented 4 years ago

Expected Behavior

i created 2 blueprint main and mobile. i expect mobile blueprint to render its own template.

blueprint = Blueprint(
        name='mobile',
        import_name=__name__,
        static_folder='assets',
        static_url_path='/mobile_assets',
        # app_cfg.APPPATH is a constant of absolute path to app root directory
        template_folder=path.join(app_cfg.APPPATH,'blueprint/mobile/template'),
    )

@blueprint.route('/', methods=['GET'])
def index_mobile():
    data = {
        'title': 'wow mobile',
        'message': 'message from mobile blueprint'
    }
    # to test if i set the corrent absolute path to the blueprint template
    print(path.join(app_cfg.APPPATH,'blueprint/mobile/template'))
    return render_template('index.html',**data)

Actual Behavior

mobile blueprint render the template from main

there is already an issue about this since 2015. but for some unknown reason its closed without mentioning any solution for this problem.

flask documention : template_folder – A folder with templates that should be added to the app’s template search path. The path is relative to the blueprint’s root path. Blueprint templates are disabled by default. Blueprint templates have a lower precedence than those in the app’s templates folder.

Environment

davidism commented 4 years ago

Duplicate of #1361

for some unknown reason its closed without mentioning any solution

Please see every reply I made in the linked duplicate for repeated explanations about what was being misunderstood and why the current implementation is intentional and will not change.

bokunodev commented 4 years ago

the problem is solved but @davidism this behaviour should be documented. well documented.

davidism commented 4 years ago

It is, in fact, well documented: https://flask.palletsprojects.com/en/1.1.x/blueprints/#templates. This was findable by searching "blueprint template" in the search box. You also quoted additional documentation about it.

So this demonstrates the fact that no matter how much I write about it, we will still get people ignoring previous discussion and insisting it isn't working correctly and isn't documented. I don't think I'm going to devote more effort to it at this point.