From coreybrett at gmail.com Thu Oct 28 16:18:47 2021 From: coreybrett at gmail.com (Corey Boyle) Date: Thu, 28 Oct 2021 16:18:47 -0400 Subject: [Flask] setting SERVER_NAME for only CLI commands Message-ID: I would like to use url_for with the _external option for generating some links inside emails that a CLI command will generate. If I set the SERVER_NAME config var, it solves this problem nicely, however, it breaks my local dev environment. How would I set the SERVER_NAME only for CLI commands? From ub at artfacts.net Thu Oct 28 17:22:24 2021 From: ub at artfacts.net (ulrich) Date: Thu, 28 Oct 2021 23:22:24 +0200 Subject: [Flask] setting SERVER_NAME for only CLI commands In-Reply-To: References: Message-ID: <2c00b67a-9a40-1cbe-7175-65a41aaf40bd@artfacts.net> hello, On 10/28/21 10:18 PM, Corey Boyle wrote: > I would like to use url_for with the _external option for generating > some links inside emails that a CLI command will generate. > > If I set the SERVER_NAME config var, it solves this problem nicely, > however, it breaks my local dev environment. how? do you not have a seperate configuration for you production environment? > How would I set the SERVER_NAME only for CLI commands? if would you like to send emails from your production environment, then why don't you employ the "classes and inheritance" pattern, suggested here: https://flask.palletsprojects.com/en/2.0.x/config/#development-production or you override SERVER_NAME from the environment: https://flask.palletsprojects.com/en/2.0.x/config/#SERVER_NAME employ dotenv to make that transparent and easy for yourself. or introduce an option to the cli command, like --server-name to set it on a per command basis explicitly. there might well be more ways and of course, what's best, depends on your usecase. best, ub > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask From coreybrett at gmail.com Thu Oct 28 19:44:01 2021 From: coreybrett at gmail.com (Corey Boyle) Date: Thu, 28 Oct 2021 19:44:01 -0400 Subject: [Flask] setting SERVER_NAME for only CLI commands In-Reply-To: <2c00b67a-9a40-1cbe-7175-65a41aaf40bd@artfacts.net> References: <2c00b67a-9a40-1cbe-7175-65a41aaf40bd@artfacts.net> Message-ID: Not sure if this would be considered a hack or not, but I ended up using... with current_app.test_request_context(base_url="https://www.xyz.com"): my_email_func() ... inside my cli function. I only wanted to set the SERVER_NAME for one particular cli script, so doing that with my config system didn't seem like the right place. On Thu, Oct 28, 2021 at 5:22 PM ulrich wrote: > hello, > > On 10/28/21 10:18 PM, Corey Boyle wrote: > > I would like to use url_for with the _external option for generating > > some links inside emails that a CLI command will generate. > > > > If I set the SERVER_NAME config var, it solves this problem nicely, > > however, it breaks my local dev environment. > > how? do you not have a seperate configuration for you production > environment? > > > How would I set the SERVER_NAME only for CLI commands? > > if would you like to send emails from your production environment, then > why don't you employ the "classes and inheritance" pattern, suggested > here: > https://flask.palletsprojects.com/en/2.0.x/config/#development-production > > or you override SERVER_NAME from the environment: > https://flask.palletsprojects.com/en/2.0.x/config/#SERVER_NAME > > employ dotenv to make that transparent and easy for yourself. > > or introduce an option to the cli command, like --server-name to set it > on a per command basis explicitly. > > there might well be more ways and of course, what's best, depends on > your usecase. > > > best, > > ub > > > > _______________________________________________ > > 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: