-
-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert from settings.py to an .env file #32
Comments
This can be a Good issue. Use enviorement variables instead a py file. Of course, there is another issue for use it with a Dictionary using a json file (#20). So i think we can use enviorement variables too. |
Seems fixed on #31 |
Hey, how can we read this settings (from |
Hola Victor creo que quizas podr'ia ayudar con esto, con un poco de guia por tu parte |
Hola Victor. Creo que tengo claro como hacerlo. La opcion de definir la configuration en settings.py va a seguir funcionando y tendrá precedencia cuando se importe settings y se llame a BlaskApp con parámetros: from blask import BlaskApp
import settings
if __name__ == '__main__':
b = BlaskApp(templateDir=settings.templateDir, postDir=settings.postDir
, defaultLayout=settings.defaultLayout,
staticDir=settings.staticDir, title=settings.title, errors={404:'404'})
b.run() Sin embargo, si se define la variable de entorno |
Add support for .env file. Close Issue zerasul#32. This Pull Request adds support to define blask settings using a .env file. **Usage** Add an .env file in the root folder defining the variables FLASK_APP, templateDir, postDir, defaultLayout, staticDir, title. (Use .env.example as template) `$ pipenv shell` will launch the virtualenv and automatically create environment variables from .env **Behaviour** In order to ensure backwards compatibility, the following precedence is considered to define blask settings: 1. if the environment variable BLASK_SETTINGS exists, the settings are loaded from this module (e.g. settings.py) 2. otherwise, environment variables, and finally default values are used 3. in any case, whenever Blask() is called with arguments, they always take precedence **Description of changes** * blask/blasksettings.py - in `BlaskSettings.__init__()``, replace default settings with environment variables. Add clarifications to docstring and comments. * blask/blaskcli.py - fix typos in comments and docstrings, minor code formatting * tests/settings_test.py - temporarily delete environment variables before the tests and restore them afterwards. Add test_from_dotenv() to test with environment variables All tests passed. Close zerasul#32.
This Pull Request adds support to define blask settings using a .env file. **Usage** Add an .env file in the root folder defining the variables FLASK_APP, templateDir, postDir, defaultLayout, staticDir, title. (Use .env.example as template) `$ pipenv shell` will launch the virtualenv and automatically create environment variables from .env **Behaviour** In order to ensure backwards compatibility, the following precedence is considered to define blask settings: 1. if the environment variable BLASK_SETTINGS exists, the settings are loaded from this module (e.g. settings.py) 2. otherwise, environment variables, and finally default values are used 3. in any case, whenever Blask() is called with arguments, they always take precedence **Description of changes** * blask/blasksettings.py - in `BlaskSettings.__init__()``, replace default settings with environment variables. Add clarifications to docstring and comments. * blask/blaskcli.py - fix typos in comments and docstrings, minor code formatting * tests/settings_test.py - temporarily delete environment variables before the tests and restore them afterwards. Add test_from_dotenv() to test with environment variables All tests passed. Close zerasul#32.
mhered-#32-read settings from dotenv file
pipenv
reads the.env
files automatically, loading the environment variables that we put into them.It is a very powerful way to correctly configure an application, following the indications of "The Twelve-Factor App".
An example of a settings.py file converted to an
.env
file could be the following:All the environment variables that we want to define, can be included in the
.env
file..gitignore
excludes the.env
file so that it can not be versioned, so that we can store sensitive data inside it.A very popular custom is to create a file
.env.example
, with sample data, so that other developers find it very easy to generate their own.env
file from the.env.example
file .The text was updated successfully, but these errors were encountered: