diff --git a/demos/polls/aiohttpdemo_polls/main.py b/demos/polls/aiohttpdemo_polls/main.py index 34469f27b59..b0949109366 100644 --- a/demos/polls/aiohttpdemo_polls/main.py +++ b/demos/polls/aiohttpdemo_polls/main.py @@ -20,12 +20,13 @@ async def close_pg(app): async def init(loop): + # load config from yaml file in current dir + conf = load_config(str(pathlib.Path('.') / 'config' / 'polls.yaml')) + # setup application and extensions app = web.Application(loop=loop) aiohttp_jinja2.setup( app, loader=jinja2.PackageLoader('aiohttpdemo_polls', 'templates')) - # load config from yaml file in current dir - conf = load_config(str(pathlib.Path('.') / 'config' / 'polls.yaml')) # create connection to the database db = await init_postgres(conf['postgres'], loop) diff --git a/docs/tutorial.rst b/docs/tutorial.rst index f67e3943e6b..bb3b5b6f3be 100644 --- a/docs/tutorial.rst +++ b/docs/tutorial.rst @@ -1,7 +1,7 @@ .. _aiohttp-tutorial: -Tutorial -======== +HTTP Server Tutorial +==================== Are you going to learn *aiohttp* but don't where to start? We have example for you. Polls application is a great example for getting @@ -69,6 +69,47 @@ Getting started with aiohttp first app This tutorial based on Django polls tutorial. +.. _aiohttp-tutorial-config: + +Configuration files +------------------- + +aiohttp is configuration agnostic. It means the library doesn't +require any configuration approach and doesn't have builtin support +for any config schema. + +But please take into account these facts: + + 1. 99% of servers have configuration files. + + 2. Every product (except Python-based solutions like Django and + Flask) doesn't store config files as part as source code. + + For example Nginx has own configuration files stored by default + under ``/etc/nginx`` folder. + + Mongo pushes config as ``/etc/mongodb.conf``. + + 3. Config files validation is good idea, strong checks may prevent + silly errors during product deployment. + +Thus we **suggest** to use the following approach: + + 1. Pushing configs as ``yaml`` files (``json`` or ``ini`` is also + good but ``yaml`` is the best). + + 2. Loading ``yaml`` config from a list of predifined locations, + e.g. ``./config/app_cfg.yaml``, ``/etc/app_cfg.yaml``. + + 3. Keeping ability to override config file by command line + parameter, e.g. ``./run_app --config=/opt/config/app_cfg.yaml``. + + 4. Applying strict validation checks to loaded dict. `trafaret + `_, `collander + `_ + or `JSON schema + `_ are good + candidates for such job. .. _aiohttp-tutorial-database: