[Flask] Template hierarchy

Corey Boyle coreybrett at gmail.com
Sun Dec 29 09:11:02 EST 2019


Check out the "EXPLAIN_TEMPLATE_LOADING" config option.
https://flask.palletsprojects.com/en/1.1.x/config/#configuration-basics

On Sun, Dec 29, 2019 at 9:00 AM onlinejudge95 <onlinejudge95 at gmail.com> wrote:
>
> Hi Mohamed,
>
> Thanks for giving time for this, but what I want is to keep the template folder outside of any blueprint folder so that I am able to reuse some components that would be common in all apps. With the approach provided here, I would have to make sure that I keep all template files related to a particular app in their respective blueprint folders. I might be mistaken here as I just went through the docs in one go.
>
> On Sun, Dec 29, 2019 at 2:21 AM Mohamed A <sim4n6 at gmail.com> wrote:
>>
>> Hi,
>>
>> Please add template_folder="templates" to the Blueprint() object creation.
>>
>> Documentation : https://flask.palletsprojects.com/en/1.1.x/blueprints/#templates
>>
>> On Sat, Dec 28, 2019 at 8:51 PM onlinejudge95 <onlinejudge95 at gmail.com> wrote:
>>>
>>> Hi Devs,
>>>
>>> I am laying out my flask app in the following manner
>>>
>>>> app
>>>>     main/
>>>>         routes.py
>>>>     static/
>>>>         css/
>>>>         js/
>>>>     templates/
>>>>         components/
>>>>         main/
>>>>             main.html
>>>> manage.py
>>>> config.py
>>>
>>>
>>> my routes.py in app/main has a blueprint route that has the following code
>>>
>>>> return render_template("main.html")
>>>
>>>
>>> on visiting /main/ in my localhost I am receiving the following error
>>>>
>>>> jinja2.exceptions.TemplateNotFound
>>>
>>>
>>> here is my factory.py
>>> import logging
>>> import os
>>> import pathlib
>>>
>>> from logging.handlers import RotatingFileHandler
>>> from dotenv import load_dotenv
>>> from flask import Flask
>>>
>>> from config import CONFIG_MAP
>>>
>>>
>>> class PythonicityServer(Flask):
>>> def __init__(self, name):
>>> load_dotenv(dotenv_path=".env")
>>> super().__init__(name)
>>>
>>> def set_logging(self):
>>> dir_path = self.config.get("LOG_DIR_PATH")
>>> file_path = self.config.get("LOG_FILE")
>>>
>>> if not pathlib.Path(dir_path).is_dir():
>>> pathlib.Path(dir_path).mkdir()
>>>
>>> file_handler = RotatingFileHandler(file_path, maxBytes=10240, backupCount=10)
>>> file_handler.setFormatter(
>>> logging.Formatter(
>>> "%(asctime)s %(levelname)s: %(message)s " "[in %(pathname)s:%(lineno)d]"
>>> )
>>> )
>>> file_handler.setLevel(logging.INFO)
>>>
>>> self.logger.addHandler(file_handler)
>>> self.logger.setLevel(logging.INFO)
>>>
>>>
>>> def create_app(env=os.getenv("FLASK_ENV")):
>>> app = PythonicityServer("pythonicity")
>>> app.config.from_object(CONFIG_MAP[env])
>>> app.set_logging()
>>>
>>> from app.main.controller import bp as main_bp
>>>
>>> app.register_blueprint(main_bp, url_prefix="/main")
>>>
>>> app.logger.info("Pythonicity startup")
>>>
>>> return app
>>>
>>>>
>>>
>>> _______________________________________________
>>> Flask mailing list
>>> Flask at python.org
>>> https://mail.python.org/mailman/listinfo/flask
>
> _______________________________________________
> Flask mailing list
> Flask at python.org
> https://mail.python.org/mailman/listinfo/flask


More information about the Flask mailing list