[Flask] Template hierarchy

Mohamed A sim4n6 at gmail.com
Sat Dec 28 15:51:19 EST 2019


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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20191228/25846d5f/attachment.html>


More information about the Flask mailing list