[Flask] setting SERVER_NAME for only CLI commands

ulrich ub at artfacts.net
Thu Oct 28 17:22:24 EDT 2021


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

> 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

or you override SERVER_NAME from the environment:

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.



> _______________________________________________
> Flask mailing list
> Flask at python.org
> https://mail.python.org/mailman/listinfo/flask

More information about the Flask mailing list