From linux4ms at gmail.com Wed Dec 4 15:28:17 2019 From: linux4ms at gmail.com (Ben Duncan) Date: Wed, 4 Dec 2019 14:28:17 -0600 Subject: [Flask] Sqlalchemy help ... Message-ID: Ok, I've gotten pretty much the session a/ blueprint figured out, even have basic slqalchemy working. I'm having trouble with flask_alchemy joins though: Application __init__.py: ...... # Globally accessible libraries pgdb = SQLAlchemy() from sqlalchemy import * from flask_sqlalchemy import SQLAlchemy metadata = MetaData() def create_app(): """Initialize the core application.""" #app = Flask(__name__, instance_relative_config=False) #app = Flask('mars') app = Flask(__name__) app.config.from_pyfile('config.cfg') # Changed session.init_app(app) #Session(app) # initialize Flask extensions #pgdb = SQLAlchemy() pgdb.app = app pgdb.init_app(app) pgdb.Model.metadata.reflect(pgdb.engine) ....... In the view: ..........(preamble stuff) from mars import pgdb class office_table(pgdb.Model): __table__ = pgdb.Model.metadata.tables['office'] class user_table(pgdb.Model): __table__ = pgdb.Model.metadata.tables['users'] # Company Routine class OfficeChoose(FlaskForm): officeid = StringField("office", validators=[DataRequired()]) @home.route('/chooseoffice', methods=['GET', 'POST']) def chooseoffice() : .... some code user_office_list = \ office_table.query.with_entities(office_table.office_number, \ office_table.office_name).all() ...... some form code office_name_sql = \ office_table.query.with_entities( office_table.office_name).\ filter_by(office_number=officeid).first() .... more route code The ABove query code works, what I do not understand is joining two tables. In Plain sql What I am trying to do is: (users table prefix of users, office table prefix of office) Select user_id, user_name, user_office, office_name From users, office where user_office = office_number ; How do I do something like this in flask_sqlalchemy ? Thanks .... ? *Ben Duncan* DBA / Chief Software Architect Mississippi State Supreme Court Electronic Filing Division -------------- next part -------------- An HTML attachment was scrubbed... URL: From daniel.watrous at Trinet.com Tue Dec 10 14:53:23 2019 From: daniel.watrous at Trinet.com (Daniel Watrous) Date: Tue, 10 Dec 2019 19:53:23 +0000 Subject: [Flask] abort(400, "my message") not returning 400 Message-ID: Hi, I have the following line in my flask application abort(400, "failure, User %s not found" % participant) When that line is executed, I get a 500 reponse, not 400. I do get the error message, but he response is embedded in HTML. 500 Internal Server Error

Internal Server Error

Error: 400 Bad Request: failure, User notauser not found

Based on the docs, I expected to get a 400 error and a non-HTML response with just he message. Is there some way to achieve this? Thanks, Daniel -------------- next part -------------- An HTML attachment was scrubbed... URL: From cal.97g at gmail.com Tue Dec 10 17:32:46 2019 From: cal.97g at gmail.com (Cal97g .) Date: Tue, 10 Dec 2019 22:32:46 +0000 Subject: [Flask] abort(400, "my message") not returning 400 In-Reply-To: References: Message-ID: Can we see where your application is initialised? Have you configured any error handlers? Many Thanks Callam Delaney On Tue, 10 Dec 2019 at 21:23, Daniel Watrous wrote: > Hi, > > > > I have the following line in my flask application > > abort(400, "failure, User %s not found" % participant) > > > > When that line is executed, I get a 500 reponse, not 400. I do get the > error message, but he response is embedded in HTML. > > > > > > 500 Internal Server Error > >

Internal Server Error

> >

Error: 400 Bad Request: failure, User notauser not found

> > > > Based on the docs, I expected to get a 400 error and a non-HTML response > with just he message. Is there some way to achieve this? > > > > Thanks, > > Daniel > > > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > -------------- next part -------------- An HTML attachment was scrubbed... URL: From daniel.watrous at Trinet.com Wed Dec 11 11:01:25 2019 From: daniel.watrous at Trinet.com (Daniel Watrous) Date: Wed, 11 Dec 2019 16:01:25 +0000 Subject: [Flask] abort(400, "my message") not returning 400 In-Reply-To: References: Message-ID: <2D9E87FC-8CE7-4F1D-90DB-56ECBB93284F@trinet.com> Callam, Thanks for the reply. I did a little more sleuthing and found that I was catching Exception in a wrapper that ensured a user was logged in. When I caught that, I threw an abort 500. When I read the documentation closer, I noticed that abort throws and HTTPExecption, so I was effectively catching that and ?changing? the abort to a 500. I removed that global Exception catch and now abort is working as expected. Daniel From: "Cal97g ." Date: Tuesday, December 10, 2019 at 4:33 PM To: Daniel Watrous Cc: "flask at python.org" Subject: Re: [Flask] abort(400, "my message") not returning 400 Can we see where your application is initialised? Have you configured any error handlers? Many Thanks Callam Delaney On Tue, 10 Dec 2019 at 21:23, Daniel Watrous > wrote: Hi, I have the following line in my flask application abort(400, "failure, User %s not found" % participant) When that line is executed, I get a 500 reponse, not 400. I do get the error message, but he response is embedded in HTML. 500 Internal Server Error

Internal Server Error

Error: 400 Bad Request: failure, User notauser not found

Based on the docs, I expected to get a 400 error and a non-HTML response with just he message. Is there some way to achieve this? Thanks, Daniel _______________________________________________ Flask mailing list Flask at python.org https://mail.python.org/mailman/listinfo/flask -------------- next part -------------- An HTML attachment was scrubbed... URL: From onlinejudge95 at gmail.com Sun Dec 15 03:13:17 2019 From: onlinejudge95 at gmail.com (Test Bot) Date: Sun, 15 Dec 2019 13:43:17 +0530 Subject: [Flask] Unable to install Flask-Mongoengine Message-ID: Hi Guys, I am unable to install *Flask-Mongoengine* using pip. Here are my specifications 1. *OS* => OSX 10.14.6 2. *Python* => Python 3.8.0 (Working in a virtualenv) 3. *Dependency Manager* => pip(19.3.1), setuptools(42.0.2) 3. *Flask-Mongoengine* => flask-mongoengine==0.9.5 I am inside my virtualenv and trying to install flask-mongoengine using > (env) $ pip install flask-mongoengine==0.9.5 Here is my error > distutils.errors.DistutilsError: Command > '['/Users/onlinejudge95/Workspace/GitHub/alma-serv/env/bin/python', '-m', > 'pip', '--disable-pip-version-check', 'wheel', '--no-deps', '-w', > '/var/folders/r7/pgqw605n55x5f9018rp72hsm0000gn/T/tmpgrvp80jd', '--quiet', > 'rednose']' returned non-zero exit status 1. Please Find attached my full error log. I am on a new system in which i installed python through the mac installer from python.org, i had run the *Install Certificates.command* for SSL related issues, if it might be of help. In case there is a more specific mailing list to redirect to, please let me know. Thanks, onlinejudge95 -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- (env) $ pip install flask-mongoengine Collecting flask-mongoengine Using cached https://files.pythonhosted.org/packages/20/53/1bb8ad34ad5c2047a11651290325e55086bc18fce7cfdbbe6f5522bd0ae5/flask-mongoengine-0.9.5.tar.gz ERROR: Command errored out with exit status 1: command: /Users/onlinejudge95/Workspace/GitHub/alma-serv/env/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/r7/pgqw605n55x5f9018rp72hsm0000gn/T/pip-install-73496mgp/flask-mongoengine/setup.py'"'"'; __file__='"'"'/private/var/folders/r7/pgqw605n55x5f9018rp72hsm0000gn/T/pip-install-73496mgp/flask-mongoengine/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/r7/pgqw605n55x5f9018rp72hsm0000gn/T/pip-install-73496mgp/flask-mongoengine/pip-egg-info cwd: /private/var/folders/r7/pgqw605n55x5f9018rp72hsm0000gn/T/pip-install-73496mgp/flask-mongoengine/ Complete output (44 lines): WARNING: The wheel package is not available. ERROR: Command errored out with exit status 1: command: /Users/onlinejudge95/Workspace/GitHub/alma-serv/env/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/r7/pgqw605n55x5f9018rp72hsm0000gn/T/pip-wheel-z44wznx3/rednose/setup.py'"'"'; __file__='"'"'/private/var/folders/r7/pgqw605n55x5f9018rp72hsm0000gn/T/pip-wheel-z44wznx3/rednose/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /private/var/folders/r7/pgqw605n55x5f9018rp72hsm0000gn/T/pip-wheel-qz9lk008 cwd: /private/var/folders/r7/pgqw605n55x5f9018rp72hsm0000gn/T/pip-wheel-z44wznx3/rednose/ Complete output (6 lines): usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...] or: setup.py --help [cmd1 cmd2 ...] or: setup.py --help-commands or: setup.py cmd --help error: invalid command 'bdist_wheel' ---------------------------------------- ERROR: Failed building wheel for rednose ERROR: Failed to build one or more wheels Traceback (most recent call last): File "/Users/onlinejudge95/Workspace/GitHub/alma-serv/env/lib/python3.8/site-packages/setuptools/installer.py", line 128, in fetch_build_egg subprocess.check_call(cmd) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/subprocess.py", line 364, in check_call raise CalledProcessError(retcode, cmd) subprocess.CalledProcessError: Command '['/Users/onlinejudge95/Workspace/GitHub/alma-serv/env/bin/python3', '-m', 'pip', '--disable-pip-version-check', 'wheel', '--no-deps', '-w', '/var/folders/r7/pgqw605n55x5f9018rp72hsm0000gn/T/tmpjzg2lnoc', '--quiet', 'rednose']' returned non-zero exit status 1. During handling of the above exception, another exception occurred: Traceback (most recent call last): File "", line 1, in File "/private/var/folders/r7/pgqw605n55x5f9018rp72hsm0000gn/T/pip-install-73496mgp/flask-mongoengine/setup.py", line 36, in setup( File "/Users/onlinejudge95/Workspace/GitHub/alma-serv/env/lib/python3.8/site-packages/setuptools/__init__.py", line 144, in setup _install_setup_requires(attrs) File "/Users/onlinejudge95/Workspace/GitHub/alma-serv/env/lib/python3.8/site-packages/setuptools/__init__.py", line 139, in _install_setup_requires dist.fetch_build_eggs(dist.setup_requires) File "/Users/onlinejudge95/Workspace/GitHub/alma-serv/env/lib/python3.8/site-packages/setuptools/dist.py", line 718, in fetch_build_eggs resolved_dists = pkg_resources.working_set.resolve( File "/Users/onlinejudge95/Workspace/GitHub/alma-serv/env/lib/python3.8/site-packages/pkg_resources/__init__.py", line 780, in resolve dist = best[req.key] = env.best_match( File "/Users/onlinejudge95/Workspace/GitHub/alma-serv/env/lib/python3.8/site-packages/pkg_resources/__init__.py", line 1065, in best_match return self.obtain(req, installer) File "/Users/onlinejudge95/Workspace/GitHub/alma-serv/env/lib/python3.8/site-packages/pkg_resources/__init__.py", line 1077, in obtain return installer(requirement) File "/Users/onlinejudge95/Workspace/GitHub/alma-serv/env/lib/python3.8/site-packages/setuptools/dist.py", line 777, in fetch_build_egg return fetch_build_egg(self, req) File "/Users/onlinejudge95/Workspace/GitHub/alma-serv/env/lib/python3.8/site-packages/setuptools/installer.py", line 130, in fetch_build_egg raise DistutilsError(str(e)) distutils.errors.DistutilsError: Command '['/Users/onlinejudge95/Workspace/GitHub/alma-serv/env/bin/python3', '-m', 'pip', '--disable-pip-version-check', 'wheel', '--no-deps', '-w', '/var/folders/r7/pgqw605n55x5f9018rp72hsm0000gn/T/tmpjzg2lnoc', '--quiet', 'rednose']' returned non-zero exit status 1. ---------------------------------------- ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output. From onlinejudge95 at gmail.com Sun Dec 15 05:36:37 2019 From: onlinejudge95 at gmail.com (Test Bot) Date: Sun, 15 Dec 2019 16:06:37 +0530 Subject: [Flask] Unable to install Flask-Mongoengine In-Reply-To: References: Message-ID: No help with using pip3 On Sun, Dec 15, 2019 at 2:49 PM tommy yama wrote: > how about pip3? > > On Sun, Dec 15, 2019 at 5:16 PM Test Bot wrote: > >> Hi Guys, >> >> I am unable to install *Flask-Mongoengine* using pip. Here are my >> specifications >> >> 1. *OS* => OSX 10.14.6 >> 2. *Python* => Python 3.8.0 (Working in a virtualenv) >> 3. *Dependency Manager* => pip(19.3.1), setuptools(42.0.2) >> 3. *Flask-Mongoengine* => flask-mongoengine==0.9.5 >> >> I am inside my virtualenv and trying to install flask-mongoengine using >> >> > (env) $ pip install flask-mongoengine==0.9.5 >> >> >> Here is my error >> >> > distutils.errors.DistutilsError: Command >> > '['/Users/onlinejudge95/Workspace/GitHub/alma-serv/env/bin/python', >> '-m', >> > 'pip', '--disable-pip-version-check', 'wheel', '--no-deps', '-w', >> > '/var/folders/r7/pgqw605n55x5f9018rp72hsm0000gn/T/tmpgrvp80jd', >> '--quiet', >> > 'rednose']' returned non-zero exit status 1. >> >> >> Please Find attached my full error log. >> >> I am on a new system in which i installed python through the mac installer >> from python.org, i had run the *Install Certificates.command* for SSL >> related issues, if it might be of help. >> >> In case there is a more specific mailing list to redirect to, please let >> me >> know. >> >> Thanks, >> onlinejudge95 >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nad at python.org Mon Dec 16 01:16:39 2019 From: nad at python.org (Ned Deily) Date: Mon, 16 Dec 2019 01:16:39 -0500 Subject: [Flask] Unable to install Flask-Mongoengine In-Reply-To: References: Message-ID: On 2019-12-15 03:13, Test Bot wrote: > I am unable to install *Flask-Mongoengine* using pip. Here are my > specifications > > 1. *OS* => OSX 10.14.6 > 2. *Python* =>?Python 3.8.0 (Working in a virtualenv) > 3. *Dependency Manager* => pip(19.3.1), setuptools(42.0.2) > 3. *Flask-Mongoengine* =>?flask-mongoengine==0.9.5 > > I am inside my virtualenv and trying to install flask-mongoengine using > > (env) $ pip install?flask-mongoengine==0.9.5 > > > Here is my error > > ?distutils.errors.DistutilsError: Command > '['/Users/onlinejudge95/Workspace/GitHub/alma-serv/env/bin/python', > '-m', 'pip', '--disable-pip-version-check', 'wheel', '--no-deps', > '-w', > '/var/folders/r7/pgqw605n55x5f9018rp72hsm0000gn/T/tmpgrvp80jd', > '--quiet', 'rednose']' returned non-zero exit status 1. You are running into an issue caused by a change in setuptools: https://github.com/pypa/setuptools/issues/1934 It looks like the simplest solution is to first install the wheel package in your venv: pip install wheel pip install flask-mongoengine==0.9.5 Either that or install a previous version of setuptools. You may want to chime in on the discussion of that issue. From onlinejudge95 at gmail.com Sat Dec 28 14:51:33 2019 From: onlinejudge95 at gmail.com (onlinejudge95) Date: Sun, 29 Dec 2019 01:21:33 +0530 Subject: [Flask] Template hierarchy Message-ID: 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: From sim4n6 at gmail.com Sat Dec 28 15:51:19 2019 From: sim4n6 at gmail.com (Mohamed A) Date: Sat, 28 Dec 2019 21:51:19 +0100 Subject: [Flask] Template hierarchy In-Reply-To: References: Message-ID: 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 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: From onlinejudge95 at gmail.com Sun Dec 29 08:59:57 2019 From: onlinejudge95 at gmail.com (onlinejudge95) Date: Sun, 29 Dec 2019 19:29:57 +0530 Subject: [Flask] Template hierarchy In-Reply-To: References: Message-ID: 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 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 > 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: From coreybrett at gmail.com Sun Dec 29 09:11:02 2019 From: coreybrett at gmail.com (Corey Boyle) Date: Sun, 29 Dec 2019 09:11:02 -0500 Subject: [Flask] Template hierarchy In-Reply-To: References: Message-ID: 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 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 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 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 From sim4n6 at gmail.com Sun Dec 29 11:13:22 2019 From: sim4n6 at gmail.com (Mohamed A) Date: Sun, 29 Dec 2019 17:13:22 +0100 Subject: [Flask] Template hierarchy In-Reply-To: References: Message-ID: Don't you think that the right way is to create a "templates" folder for each blueprint and a common "templates" at the root... and then via the blueprint template extends or includes components from the root "templates". Check out my sample demo website here please : https://github.com/Sim4n6/UR-CodingChallenge On Sun, Dec 29, 2019 at 3:11 PM Corey Boyle wrote: > 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 > 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 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 > 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 > -------------- next part -------------- An HTML attachment was scrubbed... URL: From projetmbc at gmail.com Sun Dec 29 12:10:17 2019 From: projetmbc at gmail.com (Christophe Bal) Date: Sun, 29 Dec 2019 18:10:17 +0100 Subject: [Flask] Template hierarchy In-Reply-To: References: Message-ID: This design sound better. Christophe BAL Enseignant Agr?g? de Math?matiques Programmeur Python Amateur Le dim. 29 d?c. 2019 17:14, Mohamed A a ?crit : > Don't you think that the right way is to create a "templates" folder for > each blueprint and a common "templates" at the root... and then via the > blueprint template extends or includes components from the root > "templates". > > Check out my sample demo website here please : > https://github.com/Sim4n6/UR-CodingChallenge > > > On Sun, Dec 29, 2019 at 3:11 PM Corey Boyle wrote: > >> 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 >> 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 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 >> 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 >> > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > -------------- next part -------------- An HTML attachment was scrubbed... URL: From onlinejudge95 at gmail.com Sun Dec 29 13:37:32 2019 From: onlinejudge95 at gmail.com (onlinejudge95) Date: Mon, 30 Dec 2019 00:07:32 +0530 Subject: [Flask] Template hierarchy In-Reply-To: References: Message-ID: Makes sense On Sun, Dec 29, 2019 at 9:43 PM Mohamed A wrote: > Don't you think that the right way is to create a "templates" folder for > each blueprint and a common "templates" at the root... and then via the > blueprint template extends or includes components from the root > "templates". > > Check out my sample demo website here please : > https://github.com/Sim4n6/UR-CodingChallenge > > > On Sun, Dec 29, 2019 at 3:11 PM Corey Boyle wrote: > >> 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 >> 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 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 >> 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 >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: