We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[bug] FlaskDynaconf breaks default getter of flask config
**Describe the bug**
In pure Flask config if you query config for nonexisting key you get `KeyError` exception.
If use FlaskDynaconf if you query config for nonexisting key you get value `None`.

Such differences break thirdparty libraries, which suppose that flask config will raise `KeyError` when queriing nonexisting key (for example, `python-social-auth`: https://github.com/python-social-auth/social-core/blob/master/social_core/strategy.py#L45 which goes to https://github.com/python-social-auth/social-app-flask/blob/master/social_flask/strategy.py#L19)

**To Reproduce**
Correct behavior:

```
from flask import Flask

app = Flask(__name__)
print("NON_EXISTING" in app.config)
print(app.config["NON_EXISTING"])
```

will give you

```
False
Traceback (most recent call last):
  File "dc_poc/1_no_dynaconf.py", line 6, in <module>
    print(app.config["NON_EXISTING"])
KeyError: 'NON_EXISTING'
```

Incorrect behavior:

```
from flask import Flask
from dynaconf import FlaskDynaconf

app = Flask(__name__)
FlaskDynaconf(app=app)
print("NON_EXISTING" in app.config)
print(app.config["NON_EXISTING"])
```

will give you

```
False
None
```

1. Having the following folder structure

<!-- Describe or use the command `$ tree -v` and paste below -->

<details>
<summary> Project structure </summary>

```13:57 $ tree -v
.
├── 1_no_dynaconf.py
└── 2_dynaconf.py

0 directories, 2 files
```
</details>

2. Having the following config files:

<!-- Please adjust if you are using different files and formats! -->

<details>
<summary> Config files </summary>
No config files used at all
</details>

3. Having the following app code:

<details>
<summary> Code </summary>

**1_no_dynaconf.py**
```python
from flask import Flask

app = Flask(__name__)
print("NON_EXISTING" in app.config)
print(app.config["NON_EXISTING"])
```

**2_dynaconf.py**
```python
from flask import Flask
from dynaconf import FlaskDynaconf

app = Flask(__name__)
FlaskDynaconf(app=app)
print("NON_EXISTING" in app.config)
print(app.config["NON_EXISTING"])
```
</details>

4. Executing under the following environment

<details>
<summary> Execution </summary>

used Python 3.8.5, Flask 1.1.2, dynaconf 3.1.2

```bash
# other commands and details?
# virtualenv activation?

$ python 1_no_dynaconf.py
$ python 2_dynaconf.py
```

</details>

**Expected behavior**
Queriing non existing key via `config[key]` should raise `KeyError`, not returning `None`.

**Environment (please complete the following information):**
 - OS: Linux/Kubuntu20.04
 - Dynaconf Version 3.1.2
 - Flask 1.1.2

**Additional context**
Add any other context about the problem here.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `dynaconf/contrib/flask_dynaconf.py`
Content:
```
1 import warnings
2 
3 try:
4     from flask.config import Config
5 
6     flask_installed = True
7 except ImportError:  # pragma: no cover
8     flask_installed = False
9     Config = object
10 
11 
12 import dynaconf
13 import pkg_resources
14 
15 
16 class FlaskDynaconf:
17     """The arguments are.
18     app = The created app
19     dynaconf_args = Extra args to be passed to Dynaconf (validator for example)
20 
21     All other values are stored as config vars specially::
22 
23         ENVVAR_PREFIX_FOR_DYNACONF = env prefix for your envvars to be loaded
24                             example:
25                                 if you set to `MYSITE` then
26                                 export MYSITE_SQL_PORT='@int 5445'
27 
28                             with that exported to env you access using:
29                                 app.config.SQL_PORT
30                                 app.config.get('SQL_PORT')
31                                 app.config.get('sql_port')
32                                 # get is case insensitive
33                                 app.config['SQL_PORT']
34 
35                             Dynaconf uses `@int, @bool, @float, @json` to cast
36                             env vars
37 
38         SETTINGS_FILE_FOR_DYNACONF = The name of the module or file to use as
39                                     default to load settings. If nothing is
40                                     passed it will be `settings.*` or value
41                                     found in `ENVVAR_FOR_DYNACONF`
42                                     Dynaconf supports
43                                     .py, .yml, .toml, ini, json
44 
45     ATTENTION: Take a look at `settings.yml` and `.secrets.yml` to know the
46             required settings format.
47 
48     Settings load order in Dynaconf:
49 
50     - Load all defaults and Flask defaults
51     - Load all passed variables when applying FlaskDynaconf
52     - Update with data in settings files
53     - Update with data in environment vars `ENVVAR_FOR_DYNACONF_`
54 
55 
56     TOML files are very useful to have `envd` settings, lets say,
57     `production` and `development`.
58 
59     You can also achieve the same using multiple `.py` files naming as
60     `settings.py`, `production_settings.py` and `development_settings.py`
61     (see examples/validator)
62 
63     Example::
64 
65         app = Flask(__name__)
66         FlaskDynaconf(
67             app,
68             ENV='MYSITE',
69             SETTINGS_FILE='settings.yml',
70             EXTRA_VALUE='You can add aditional config vars here'
71         )
72 
73     Take a look at examples/flask in Dynaconf repository
74 
75     """
76 
77     def __init__(
78         self,
79         app=None,
80         instance_relative_config=False,
81         dynaconf_instance=None,
82         extensions_list=False,
83         **kwargs,
84     ):
85         """kwargs holds initial dynaconf configuration"""
86         if not flask_installed:  # pragma: no cover
87             raise RuntimeError(
88                 "To use this extension Flask must be installed "
89                 "install it with: pip install flask"
90             )
91         self.kwargs = kwargs
92 
93         kwargs.setdefault("ENVVAR_PREFIX", "FLASK")
94         env_prefix = f"{kwargs['ENVVAR_PREFIX']}_ENV"  # FLASK_ENV
95         kwargs.setdefault("ENV_SWITCHER", env_prefix)
96         kwargs.setdefault("ENVIRONMENTS", True)
97         kwargs.setdefault("load_dotenv", True)
98         kwargs.setdefault(
99             "default_settings_paths", dynaconf.DEFAULT_SETTINGS_FILES
100         )
101 
102         self.dynaconf_instance = dynaconf_instance
103         self.instance_relative_config = instance_relative_config
104         self.extensions_list = extensions_list
105         if app:
106             self.init_app(app, **kwargs)
107 
108     def init_app(self, app, **kwargs):
109         """kwargs holds initial dynaconf configuration"""
110         self.kwargs.update(kwargs)
111         self.settings = self.dynaconf_instance or dynaconf.LazySettings(
112             **self.kwargs
113         )
114         dynaconf.settings = self.settings  # rebind customized settings
115         app.config = self.make_config(app)
116         app.dynaconf = self.settings
117 
118         if self.extensions_list:
119             if not isinstance(self.extensions_list, str):
120                 self.extensions_list = "EXTENSIONS"
121             app.config.load_extensions(self.extensions_list)
122 
123     def make_config(self, app):
124         root_path = app.root_path
125         if self.instance_relative_config:  # pragma: no cover
126             root_path = app.instance_path
127         if self.dynaconf_instance:
128             self.settings.update(self.kwargs)
129         return DynaconfConfig(
130             root_path=root_path,
131             defaults=app.config,
132             _settings=self.settings,
133             _app=app,
134         )
135 
136 
137 class DynaconfConfig(Config):
138     """
139     Settings load order in Dynaconf:
140 
141     - Load all defaults and Flask defaults
142     - Load all passed variables when applying FlaskDynaconf
143     - Update with data in settings files
144     - Update with data in environmente vars `ENV_FOR_DYNACONF_`
145     """
146 
147     def __init__(self, _settings, _app, *args, **kwargs):
148         """perform the initial load"""
149         super(DynaconfConfig, self).__init__(*args, **kwargs)
150         Config.update(self, _settings.store)
151         self._settings = _settings
152         self._app = _app
153 
154     def __contains__(self, item):
155         return hasattr(self, item)
156 
157     def __getitem__(self, key):
158         """
159         Flask templates always expects a None when key is not found in config
160         """
161         return self.get(key)
162 
163     def __setitem__(self, key, value):
164         """
165         Allows app.config['key'] = 'foo'
166         """
167         return self._settings.__setitem__(key, value)
168 
169     def __getattr__(self, name):
170         """
171         First try to get value from dynaconf then from Flask
172         """
173         try:
174             return getattr(self._settings, name)
175         except AttributeError:
176             return self[name]
177 
178     def __call__(self, name, *args, **kwargs):
179         return self.get(name, *args, **kwargs)
180 
181     def get(self, key, default=None):
182         """Gets config from dynaconf variables
183         if variables does not exists in dynaconf try getting from
184         `app.config` to support runtime settings."""
185         return self._settings.get(key, Config.get(self, key, default))
186 
187     def load_extensions(self, key="EXTENSIONS", app=None):
188         """Loads flask extensions dynamically."""
189         app = app or self._app
190         extensions = app.config.get(key)
191         if not extensions:
192             warnings.warn(
193                 f"Settings is missing {key} to load Flask Extensions",
194                 RuntimeWarning,
195             )
196             return
197 
198         for object_reference in app.config[key]:
199             # add a placeholder `name` to create a valid entry point
200             entry_point_spec = f"__name = {object_reference}"
201             # parse the entry point specification
202             entry_point = pkg_resources.EntryPoint.parse(entry_point_spec)
203             # dynamically resolve the entry point
204             initializer = entry_point.resolve()
205             # Invoke extension initializer
206             initializer(app)
207
```

Path: `example/issues/194_flask_config/app.py`
Content:
```
1 from flask import Flask
2 
3 from dynaconf import FlaskDynaconf
4 from dynaconf import settings
5 
6 
7 app = Flask(__name__)
8 
9 settings["MESSAGE"] = "hello"
10 assert settings["MESSAGE"] == "hello"
11 
12 FlaskDynaconf(app, dynaconf_instance=settings)
13 
14 assert app.config["MESSAGE"] == "hello"
15 
16 app.config.set("MESSAGE", "bye")
17 
18 assert app.config["MESSAGE"] == "bye"
19 
20 
21 app.config["MESSAGE"] = "bazinga"
22 
23 assert app.config["MESSAGE"] == "bazinga"
24
```

Path: `example/flask_with_dotenv/app.py`
Content:
```
1 from flask import Flask
2 from flask import render_template
3 
4 from dynaconf.contrib import FlaskDynaconf
5 
6 # create your app
7 app = Flask(__name__)
8 
9 # will populate app.config from .env + environment variables
10 FlaskDynaconf(app)
11 
12 
13 @app.route("/")
14 def index():
15     return render_template("dynaconf.html")
16 
17 
18 @app.route("/test")
19 def test():
20     return app.config["HELLO"]
21 
22 
23 app.add_url_rule(app.config.TEST_RULE, view_func=lambda: "test")
24 
25 
26 if __name__ == "__main__":
27     app.run()
28
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/dynaconf/contrib/flask_dynaconf.py b/dynaconf/contrib/flask_dynaconf.py
--- a/dynaconf/contrib/flask_dynaconf.py
+++ b/dynaconf/contrib/flask_dynaconf.py
@@ -151,14 +151,11 @@
         self._settings = _settings
         self._app = _app
 
-    def __contains__(self, item):
-        return hasattr(self, item)
-
     def __getitem__(self, key):
-        """
-        Flask templates always expects a None when key is not found in config
-        """
-        return self.get(key)
+        try:
+            return self._settings[key]
+        except KeyError:
+            return Config.__getitem__(self, key)
 
     def __setitem__(self, key, value):
         """
@@ -168,7 +165,7 @@
 
     def __getattr__(self, name):
         """
-        First try to get value from dynaconf then from Flask
+        First try to get value from dynaconf then from Flask Config
         """
         try:
             return getattr(self._settings, name)
diff --git a/example/flask_with_dotenv/app.py b/example/flask_with_dotenv/app.py
--- a/example/flask_with_dotenv/app.py
+++ b/example/flask_with_dotenv/app.py
@@ -20,7 +20,9 @@
     return app.config["HELLO"]
 
 
-app.add_url_rule(app.config.TEST_RULE, view_func=lambda: "test")
+app.add_url_rule(
+    app.config.get("TEST_RULE", "/default_route"), view_func=lambda: "test"
+)
 
 
 if __name__ == "__main__":
diff --git a/example/issues/194_flask_config/app.py b/example/issues/194_flask_config/app.py
--- a/example/issues/194_flask_config/app.py
+++ b/example/issues/194_flask_config/app.py
@@ -15,7 +15,7 @@
 
 app.config.set("MESSAGE", "bye")
 
-assert app.config["MESSAGE"] == "bye"
+assert app.config["MESSAGE"] == "bye", app.config["MESSAGE"]
 
 
 app.config["MESSAGE"] = "bazinga"

{"golden_diff": "diff --git a/dynaconf/contrib/flask_dynaconf.py b/dynaconf/contrib/flask_dynaconf.py\n--- a/dynaconf/contrib/flask_dynaconf.py\n+++ b/dynaconf/contrib/flask_dynaconf.py\n@@ -151,14 +151,11 @@\n         self._settings = _settings\n         self._app = _app\n \n-    def __contains__(self, item):\n-        return hasattr(self, item)\n-\n     def __getitem__(self, key):\n-        \"\"\"\n-        Flask templates always expects a None when key is not found in config\n-        \"\"\"\n-        return self.get(key)\n+        try:\n+            return self._settings[key]\n+        except KeyError:\n+            return Config.__getitem__(self, key)\n \n     def __setitem__(self, key, value):\n         \"\"\"\n@@ -168,7 +165,7 @@\n \n     def __getattr__(self, name):\n         \"\"\"\n-        First try to get value from dynaconf then from Flask\n+        First try to get value from dynaconf then from Flask Config\n         \"\"\"\n         try:\n             return getattr(self._settings, name)\ndiff --git a/example/flask_with_dotenv/app.py b/example/flask_with_dotenv/app.py\n--- a/example/flask_with_dotenv/app.py\n+++ b/example/flask_with_dotenv/app.py\n@@ -20,7 +20,9 @@\n     return app.config[\"HELLO\"]\n \n \n-app.add_url_rule(app.config.TEST_RULE, view_func=lambda: \"test\")\n+app.add_url_rule(\n+    app.config.get(\"TEST_RULE\", \"/default_route\"), view_func=lambda: \"test\"\n+)\n \n \n if __name__ == \"__main__\":\ndiff --git a/example/issues/194_flask_config/app.py b/example/issues/194_flask_config/app.py\n--- a/example/issues/194_flask_config/app.py\n+++ b/example/issues/194_flask_config/app.py\n@@ -15,7 +15,7 @@\n \n app.config.set(\"MESSAGE\", \"bye\")\n \n-assert app.config[\"MESSAGE\"] == \"bye\"\n+assert app.config[\"MESSAGE\"] == \"bye\", app.config[\"MESSAGE\"]\n \n \n app.config[\"MESSAGE\"] = \"bazinga\"\n", "issue": "[bug] FlaskDynaconf breaks default getter of flask config\n**Describe the bug**\r\nIn pure Flask config if you query config for nonexisting key you get `KeyError` exception.\r\nIf use FlaskDynaconf if you query config for nonexisting key you get value `None`.\r\n\r\nSuch differences break thirdparty libraries, which suppose that flask config will raise `KeyError` when queriing nonexisting key (for example, `python-social-auth`: https://github.com/python-social-auth/social-core/blob/master/social_core/strategy.py#L45 which goes to https://github.com/python-social-auth/social-app-flask/blob/master/social_flask/strategy.py#L19)\r\n\r\n**To Reproduce**\r\nCorrect behavior:\r\n\r\n```\r\nfrom flask import Flask\r\n\r\napp = Flask(__name__)\r\nprint(\"NON_EXISTING\" in app.config)\r\nprint(app.config[\"NON_EXISTING\"])\r\n```\r\n\r\nwill give you\r\n\r\n```\r\nFalse\r\nTraceback (most recent call last):\r\n  File \"dc_poc/1_no_dynaconf.py\", line 6, in <module>\r\n    print(app.config[\"NON_EXISTING\"])\r\nKeyError: 'NON_EXISTING'\r\n```\r\n\r\nIncorrect behavior:\r\n\r\n```\r\nfrom flask import Flask\r\nfrom dynaconf import FlaskDynaconf\r\n\r\napp = Flask(__name__)\r\nFlaskDynaconf(app=app)\r\nprint(\"NON_EXISTING\" in app.config)\r\nprint(app.config[\"NON_EXISTING\"])\r\n```\r\n\r\nwill give you\r\n\r\n```\r\nFalse\r\nNone\r\n```\r\n\r\n1. Having the following folder structure\r\n\r\n<!-- Describe or use the command `$ tree -v` and paste below -->\r\n\r\n<details>\r\n<summary> Project structure </summary>\r\n\r\n```13:57 $ tree -v\r\n.\r\n\u251c\u2500\u2500 1_no_dynaconf.py\r\n\u2514\u2500\u2500 2_dynaconf.py\r\n\r\n0 directories, 2 files\r\n```\r\n</details>\r\n\r\n2. Having the following config files:\r\n\r\n<!-- Please adjust if you are using different files and formats! -->\r\n\r\n<details>\r\n<summary> Config files </summary>\r\nNo config files used at all\r\n</details>\r\n\r\n3. Having the following app code:\r\n\r\n<details>\r\n<summary> Code </summary>\r\n\r\n**1_no_dynaconf.py**\r\n```python\r\nfrom flask import Flask\r\n\r\napp = Flask(__name__)\r\nprint(\"NON_EXISTING\" in app.config)\r\nprint(app.config[\"NON_EXISTING\"])\r\n```\r\n\r\n**2_dynaconf.py**\r\n```python\r\nfrom flask import Flask\r\nfrom dynaconf import FlaskDynaconf\r\n\r\napp = Flask(__name__)\r\nFlaskDynaconf(app=app)\r\nprint(\"NON_EXISTING\" in app.config)\r\nprint(app.config[\"NON_EXISTING\"])\r\n```\r\n</details>\r\n\r\n4. Executing under the following environment\r\n\r\n<details>\r\n<summary> Execution </summary>\r\n\r\nused Python 3.8.5, Flask 1.1.2, dynaconf 3.1.2\r\n\r\n```bash\r\n# other commands and details?\r\n# virtualenv activation?\r\n\r\n$ python 1_no_dynaconf.py\r\n$ python 2_dynaconf.py\r\n```\r\n\r\n</details>\r\n\r\n**Expected behavior**\r\nQueriing non existing key via `config[key]` should raise `KeyError`, not returning `None`.\r\n\r\n**Environment (please complete the following information):**\r\n - OS: Linux/Kubuntu20.04\r\n - Dynaconf Version 3.1.2\r\n - Flask 1.1.2\r\n\r\n**Additional context**\r\nAdd any other context about the problem here.\r\n\n", "before_files": [{"content": "import warnings\n\ntry:\n    from flask.config import Config\n\n    flask_installed = True\nexcept ImportError:  # pragma: no cover\n    flask_installed = False\n    Config = object\n\n\nimport dynaconf\nimport pkg_resources\n\n\nclass FlaskDynaconf:\n    \"\"\"The arguments are.\n    app = The created app\n    dynaconf_args = Extra args to be passed to Dynaconf (validator for example)\n\n    All other values are stored as config vars specially::\n\n        ENVVAR_PREFIX_FOR_DYNACONF = env prefix for your envvars to be loaded\n                            example:\n                                if you set to `MYSITE` then\n                                export MYSITE_SQL_PORT='@int 5445'\n\n                            with that exported to env you access using:\n                                app.config.SQL_PORT\n                                app.config.get('SQL_PORT')\n                                app.config.get('sql_port')\n                                # get is case insensitive\n                                app.config['SQL_PORT']\n\n                            Dynaconf uses `@int, @bool, @float, @json` to cast\n                            env vars\n\n        SETTINGS_FILE_FOR_DYNACONF = The name of the module or file to use as\n                                    default to load settings. If nothing is\n                                    passed it will be `settings.*` or value\n                                    found in `ENVVAR_FOR_DYNACONF`\n                                    Dynaconf supports\n                                    .py, .yml, .toml, ini, json\n\n    ATTENTION: Take a look at `settings.yml` and `.secrets.yml` to know the\n            required settings format.\n\n    Settings load order in Dynaconf:\n\n    - Load all defaults and Flask defaults\n    - Load all passed variables when applying FlaskDynaconf\n    - Update with data in settings files\n    - Update with data in environment vars `ENVVAR_FOR_DYNACONF_`\n\n\n    TOML files are very useful to have `envd` settings, lets say,\n    `production` and `development`.\n\n    You can also achieve the same using multiple `.py` files naming as\n    `settings.py`, `production_settings.py` and `development_settings.py`\n    (see examples/validator)\n\n    Example::\n\n        app = Flask(__name__)\n        FlaskDynaconf(\n            app,\n            ENV='MYSITE',\n            SETTINGS_FILE='settings.yml',\n            EXTRA_VALUE='You can add aditional config vars here'\n        )\n\n    Take a look at examples/flask in Dynaconf repository\n\n    \"\"\"\n\n    def __init__(\n        self,\n        app=None,\n        instance_relative_config=False,\n        dynaconf_instance=None,\n        extensions_list=False,\n        **kwargs,\n    ):\n        \"\"\"kwargs holds initial dynaconf configuration\"\"\"\n        if not flask_installed:  # pragma: no cover\n            raise RuntimeError(\n                \"To use this extension Flask must be installed \"\n                \"install it with: pip install flask\"\n            )\n        self.kwargs = kwargs\n\n        kwargs.setdefault(\"ENVVAR_PREFIX\", \"FLASK\")\n        env_prefix = f\"{kwargs['ENVVAR_PREFIX']}_ENV\"  # FLASK_ENV\n        kwargs.setdefault(\"ENV_SWITCHER\", env_prefix)\n        kwargs.setdefault(\"ENVIRONMENTS\", True)\n        kwargs.setdefault(\"load_dotenv\", True)\n        kwargs.setdefault(\n            \"default_settings_paths\", dynaconf.DEFAULT_SETTINGS_FILES\n        )\n\n        self.dynaconf_instance = dynaconf_instance\n        self.instance_relative_config = instance_relative_config\n        self.extensions_list = extensions_list\n        if app:\n            self.init_app(app, **kwargs)\n\n    def init_app(self, app, **kwargs):\n        \"\"\"kwargs holds initial dynaconf configuration\"\"\"\n        self.kwargs.update(kwargs)\n        self.settings = self.dynaconf_instance or dynaconf.LazySettings(\n            **self.kwargs\n        )\n        dynaconf.settings = self.settings  # rebind customized settings\n        app.config = self.make_config(app)\n        app.dynaconf = self.settings\n\n        if self.extensions_list:\n            if not isinstance(self.extensions_list, str):\n                self.extensions_list = \"EXTENSIONS\"\n            app.config.load_extensions(self.extensions_list)\n\n    def make_config(self, app):\n        root_path = app.root_path\n        if self.instance_relative_config:  # pragma: no cover\n            root_path = app.instance_path\n        if self.dynaconf_instance:\n            self.settings.update(self.kwargs)\n        return DynaconfConfig(\n            root_path=root_path,\n            defaults=app.config,\n            _settings=self.settings,\n            _app=app,\n        )\n\n\nclass DynaconfConfig(Config):\n    \"\"\"\n    Settings load order in Dynaconf:\n\n    - Load all defaults and Flask defaults\n    - Load all passed variables when applying FlaskDynaconf\n    - Update with data in settings files\n    - Update with data in environmente vars `ENV_FOR_DYNACONF_`\n    \"\"\"\n\n    def __init__(self, _settings, _app, *args, **kwargs):\n        \"\"\"perform the initial load\"\"\"\n        super(DynaconfConfig, self).__init__(*args, **kwargs)\n        Config.update(self, _settings.store)\n        self._settings = _settings\n        self._app = _app\n\n    def __contains__(self, item):\n        return hasattr(self, item)\n\n    def __getitem__(self, key):\n        \"\"\"\n        Flask templates always expects a None when key is not found in config\n        \"\"\"\n        return self.get(key)\n\n    def __setitem__(self, key, value):\n        \"\"\"\n        Allows app.config['key'] = 'foo'\n        \"\"\"\n        return self._settings.__setitem__(key, value)\n\n    def __getattr__(self, name):\n        \"\"\"\n        First try to get value from dynaconf then from Flask\n        \"\"\"\n        try:\n            return getattr(self._settings, name)\n        except AttributeError:\n            return self[name]\n\n    def __call__(self, name, *args, **kwargs):\n        return self.get(name, *args, **kwargs)\n\n    def get(self, key, default=None):\n        \"\"\"Gets config from dynaconf variables\n        if variables does not exists in dynaconf try getting from\n        `app.config` to support runtime settings.\"\"\"\n        return self._settings.get(key, Config.get(self, key, default))\n\n    def load_extensions(self, key=\"EXTENSIONS\", app=None):\n        \"\"\"Loads flask extensions dynamically.\"\"\"\n        app = app or self._app\n        extensions = app.config.get(key)\n        if not extensions:\n            warnings.warn(\n                f\"Settings is missing {key} to load Flask Extensions\",\n                RuntimeWarning,\n            )\n            return\n\n        for object_reference in app.config[key]:\n            # add a placeholder `name` to create a valid entry point\n            entry_point_spec = f\"__name = {object_reference}\"\n            # parse the entry point specification\n            entry_point = pkg_resources.EntryPoint.parse(entry_point_spec)\n            # dynamically resolve the entry point\n            initializer = entry_point.resolve()\n            # Invoke extension initializer\n            initializer(app)\n", "path": "dynaconf/contrib/flask_dynaconf.py"}, {"content": "from flask import Flask\n\nfrom dynaconf import FlaskDynaconf\nfrom dynaconf import settings\n\n\napp = Flask(__name__)\n\nsettings[\"MESSAGE\"] = \"hello\"\nassert settings[\"MESSAGE\"] == \"hello\"\n\nFlaskDynaconf(app, dynaconf_instance=settings)\n\nassert app.config[\"MESSAGE\"] == \"hello\"\n\napp.config.set(\"MESSAGE\", \"bye\")\n\nassert app.config[\"MESSAGE\"] == \"bye\"\n\n\napp.config[\"MESSAGE\"] = \"bazinga\"\n\nassert app.config[\"MESSAGE\"] == \"bazinga\"\n", "path": "example/issues/194_flask_config/app.py"}, {"content": "from flask import Flask\nfrom flask import render_template\n\nfrom dynaconf.contrib import FlaskDynaconf\n\n# create your app\napp = Flask(__name__)\n\n# will populate app.config from .env + environment variables\nFlaskDynaconf(app)\n\n\n@app.route(\"/\")\ndef index():\n    return render_template(\"dynaconf.html\")\n\n\n@app.route(\"/test\")\ndef test():\n    return app.config[\"HELLO\"]\n\n\napp.add_url_rule(app.config.TEST_RULE, view_func=lambda: \"test\")\n\n\nif __name__ == \"__main__\":\n    app.run()\n", "path": "example/flask_with_dotenv/app.py"}], "after_files": [{"content": "import warnings\n\ntry:\n    from flask.config import Config\n\n    flask_installed = True\nexcept ImportError:  # pragma: no cover\n    flask_installed = False\n    Config = object\n\n\nimport dynaconf\nimport pkg_resources\n\n\nclass FlaskDynaconf:\n    \"\"\"The arguments are.\n    app = The created app\n    dynaconf_args = Extra args to be passed to Dynaconf (validator for example)\n\n    All other values are stored as config vars specially::\n\n        ENVVAR_PREFIX_FOR_DYNACONF = env prefix for your envvars to be loaded\n                            example:\n                                if you set to `MYSITE` then\n                                export MYSITE_SQL_PORT='@int 5445'\n\n                            with that exported to env you access using:\n                                app.config.SQL_PORT\n                                app.config.get('SQL_PORT')\n                                app.config.get('sql_port')\n                                # get is case insensitive\n                                app.config['SQL_PORT']\n\n                            Dynaconf uses `@int, @bool, @float, @json` to cast\n                            env vars\n\n        SETTINGS_FILE_FOR_DYNACONF = The name of the module or file to use as\n                                    default to load settings. If nothing is\n                                    passed it will be `settings.*` or value\n                                    found in `ENVVAR_FOR_DYNACONF`\n                                    Dynaconf supports\n                                    .py, .yml, .toml, ini, json\n\n    ATTENTION: Take a look at `settings.yml` and `.secrets.yml` to know the\n            required settings format.\n\n    Settings load order in Dynaconf:\n\n    - Load all defaults and Flask defaults\n    - Load all passed variables when applying FlaskDynaconf\n    - Update with data in settings files\n    - Update with data in environment vars `ENVVAR_FOR_DYNACONF_`\n\n\n    TOML files are very useful to have `envd` settings, lets say,\n    `production` and `development`.\n\n    You can also achieve the same using multiple `.py` files naming as\n    `settings.py`, `production_settings.py` and `development_settings.py`\n    (see examples/validator)\n\n    Example::\n\n        app = Flask(__name__)\n        FlaskDynaconf(\n            app,\n            ENV='MYSITE',\n            SETTINGS_FILE='settings.yml',\n            EXTRA_VALUE='You can add aditional config vars here'\n        )\n\n    Take a look at examples/flask in Dynaconf repository\n\n    \"\"\"\n\n    def __init__(\n        self,\n        app=None,\n        instance_relative_config=False,\n        dynaconf_instance=None,\n        extensions_list=False,\n        **kwargs,\n    ):\n        \"\"\"kwargs holds initial dynaconf configuration\"\"\"\n        if not flask_installed:  # pragma: no cover\n            raise RuntimeError(\n                \"To use this extension Flask must be installed \"\n                \"install it with: pip install flask\"\n            )\n        self.kwargs = kwargs\n\n        kwargs.setdefault(\"ENVVAR_PREFIX\", \"FLASK\")\n        env_prefix = f\"{kwargs['ENVVAR_PREFIX']}_ENV\"  # FLASK_ENV\n        kwargs.setdefault(\"ENV_SWITCHER\", env_prefix)\n        kwargs.setdefault(\"ENVIRONMENTS\", True)\n        kwargs.setdefault(\"load_dotenv\", True)\n        kwargs.setdefault(\n            \"default_settings_paths\", dynaconf.DEFAULT_SETTINGS_FILES\n        )\n\n        self.dynaconf_instance = dynaconf_instance\n        self.instance_relative_config = instance_relative_config\n        self.extensions_list = extensions_list\n        if app:\n            self.init_app(app, **kwargs)\n\n    def init_app(self, app, **kwargs):\n        \"\"\"kwargs holds initial dynaconf configuration\"\"\"\n        self.kwargs.update(kwargs)\n        self.settings = self.dynaconf_instance or dynaconf.LazySettings(\n            **self.kwargs\n        )\n        dynaconf.settings = self.settings  # rebind customized settings\n        app.config = self.make_config(app)\n        app.dynaconf = self.settings\n\n        if self.extensions_list:\n            if not isinstance(self.extensions_list, str):\n                self.extensions_list = \"EXTENSIONS\"\n            app.config.load_extensions(self.extensions_list)\n\n    def make_config(self, app):\n        root_path = app.root_path\n        if self.instance_relative_config:  # pragma: no cover\n            root_path = app.instance_path\n        if self.dynaconf_instance:\n            self.settings.update(self.kwargs)\n        return DynaconfConfig(\n            root_path=root_path,\n            defaults=app.config,\n            _settings=self.settings,\n            _app=app,\n        )\n\n\nclass DynaconfConfig(Config):\n    \"\"\"\n    Settings load order in Dynaconf:\n\n    - Load all defaults and Flask defaults\n    - Load all passed variables when applying FlaskDynaconf\n    - Update with data in settings files\n    - Update with data in environmente vars `ENV_FOR_DYNACONF_`\n    \"\"\"\n\n    def __init__(self, _settings, _app, *args, **kwargs):\n        \"\"\"perform the initial load\"\"\"\n        super(DynaconfConfig, self).__init__(*args, **kwargs)\n        Config.update(self, _settings.store)\n        self._settings = _settings\n        self._app = _app\n\n    def __getitem__(self, key):\n        try:\n            return self._settings[key]\n        except KeyError:\n            return Config.__getitem__(self, key)\n\n    def __setitem__(self, key, value):\n        \"\"\"\n        Allows app.config['key'] = 'foo'\n        \"\"\"\n        return self._settings.__setitem__(key, value)\n\n    def __getattr__(self, name):\n        \"\"\"\n        First try to get value from dynaconf then from Flask Config\n        \"\"\"\n        try:\n            return getattr(self._settings, name)\n        except AttributeError:\n            return self[name]\n\n    def __call__(self, name, *args, **kwargs):\n        return self.get(name, *args, **kwargs)\n\n    def get(self, key, default=None):\n        \"\"\"Gets config from dynaconf variables\n        if variables does not exists in dynaconf try getting from\n        `app.config` to support runtime settings.\"\"\"\n        return self._settings.get(key, Config.get(self, key, default))\n\n    def load_extensions(self, key=\"EXTENSIONS\", app=None):\n        \"\"\"Loads flask extensions dynamically.\"\"\"\n        app = app or self._app\n        extensions = app.config.get(key)\n        if not extensions:\n            warnings.warn(\n                f\"Settings is missing {key} to load Flask Extensions\",\n                RuntimeWarning,\n            )\n            return\n\n        for object_reference in app.config[key]:\n            # add a placeholder `name` to create a valid entry point\n            entry_point_spec = f\"__name = {object_reference}\"\n            # parse the entry point specification\n            entry_point = pkg_resources.EntryPoint.parse(entry_point_spec)\n            # dynamically resolve the entry point\n            initializer = entry_point.resolve()\n            # Invoke extension initializer\n            initializer(app)\n", "path": "dynaconf/contrib/flask_dynaconf.py"}, {"content": "from flask import Flask\n\nfrom dynaconf import FlaskDynaconf\nfrom dynaconf import settings\n\n\napp = Flask(__name__)\n\nsettings[\"MESSAGE\"] = \"hello\"\nassert settings[\"MESSAGE\"] == \"hello\"\n\nFlaskDynaconf(app, dynaconf_instance=settings)\n\nassert app.config[\"MESSAGE\"] == \"hello\"\n\napp.config.set(\"MESSAGE\", \"bye\")\n\nassert app.config[\"MESSAGE\"] == \"bye\", app.config[\"MESSAGE\"]\n\n\napp.config[\"MESSAGE\"] = \"bazinga\"\n\nassert app.config[\"MESSAGE\"] == \"bazinga\"\n", "path": "example/issues/194_flask_config/app.py"}, {"content": "from flask import Flask\nfrom flask import render_template\n\nfrom dynaconf.contrib import FlaskDynaconf\n\n# create your app\napp = Flask(__name__)\n\n# will populate app.config from .env + environment variables\nFlaskDynaconf(app)\n\n\n@app.route(\"/\")\ndef index():\n    return render_template(\"dynaconf.html\")\n\n\n@app.route(\"/test\")\ndef test():\n    return app.config[\"HELLO\"]\n\n\napp.add_url_rule(\n    app.config.get(\"TEST_RULE\", \"/default_route\"), view_func=lambda: \"test\"\n)\n\n\nif __name__ == \"__main__\":\n    app.run()\n", "path": "example/flask_with_dotenv/app.py"}]}