Open picsldev opened 6 years ago
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 .env
file) to use them on Blask?
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. Entiendo que queremos que settings.py siga funcionando para tener retrocompatibilidad, pero ¿con que precedencia?
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 BLASK_SETTINGS
y tambien hay un .env, ¿a cual de las dos opciones doy prioridad? ¿Permito que se combinen variables de las dos fuentes? (ej. usar defaultLayout
de settings.py y title
de .env)
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 .