From 76b970dac6ebac08f31544f439fc9891c94083ae Mon Sep 17 00:00:00 2001 From: kirill Date: Sat, 27 May 2023 22:06:01 +0300 Subject: [PATCH 1/3] init commit --- .gitignore | 2 + demo/__init__.py | 1 + demo/app.py | 13 ++++++ demo/routes.py | 6 +++ demo/templates/index.html | 97 +++++++++++++++++++++++++++++++++++++++ demo/views/__init__.py | 1 + demo/views/frontend.py | 13 ++++++ entry.py | 14 ++++++ 8 files changed, 147 insertions(+) create mode 100644 .gitignore create mode 100644 demo/__init__.py create mode 100644 demo/app.py create mode 100644 demo/routes.py create mode 100644 demo/templates/index.html create mode 100644 demo/views/__init__.py create mode 100644 demo/views/frontend.py create mode 100644 entry.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fa2cadf --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +demo/__pycache__ +demo/views/__pycache__ diff --git a/demo/__init__.py b/demo/__init__.py new file mode 100644 index 0000000..b23f70e --- /dev/null +++ b/demo/__init__.py @@ -0,0 +1 @@ +from .app import create_app \ No newline at end of file diff --git a/demo/app.py b/demo/app.py new file mode 100644 index 0000000..4fe0516 --- /dev/null +++ b/demo/app.py @@ -0,0 +1,13 @@ +from aiohttp import web +import jinja2 +from .routes import setup_routes +import aiohttp_jinja2 + + +async def create_app(): + app = web.Application() + aiohttp_jinja2.setup(app, + loader = jinja2.PackageLoader('demo', 'templates') + ) + setup_routes(app) + return app diff --git a/demo/routes.py b/demo/routes.py new file mode 100644 index 0000000..f333bef --- /dev/null +++ b/demo/routes.py @@ -0,0 +1,6 @@ +from .views import frontend +import aiohttp + +def setup_routes(app): + app.router.add_routes([aiohttp.web.get('/', frontend.index), aiohttp.web.post('/button-clicked', frontend.button_clicked)]) + \ No newline at end of file diff --git a/demo/templates/index.html b/demo/templates/index.html new file mode 100644 index 0000000..a613686 --- /dev/null +++ b/demo/templates/index.html @@ -0,0 +1,97 @@ + + + + + Знакомство с aiohttp + + + + +
+

Знакомство с aiohttp

+
+
+
+

+
+
+ + + diff --git a/demo/views/__init__.py b/demo/views/__init__.py new file mode 100644 index 0000000..76c69e8 --- /dev/null +++ b/demo/views/__init__.py @@ -0,0 +1 @@ +from . import frontend \ No newline at end of file diff --git a/demo/views/frontend.py b/demo/views/frontend.py new file mode 100644 index 0000000..25525d2 --- /dev/null +++ b/demo/views/frontend.py @@ -0,0 +1,13 @@ +import aiohttp + +from aiohttp_jinja2 import template + + + +@template('index.html') +async def index(request): + return {} + + +async def button_clicked(request): + return aiohttp.web.json_response({'result':'Button was clicked'}) \ No newline at end of file diff --git a/entry.py b/entry.py new file mode 100644 index 0000000..de968e0 --- /dev/null +++ b/entry.py @@ -0,0 +1,14 @@ +import aiohttp +from demo import create_app + + + + + +app = create_app() + + + + +if __name__ == '__main__': + aiohttp.web.run_app(app) \ No newline at end of file From e46f411734136f76bee40f6060147cc2ba11cb1c Mon Sep 17 00:00:00 2001 From: Regela Date: Sat, 27 May 2023 22:26:50 +0300 Subject: [PATCH 2/3] Add requirements --- requirements.txt | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 requirements.txt diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..dfb4018 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +aiohttp~=3.8.4 +Jinja2~=3.1.2 \ No newline at end of file From 25cd1944e1672b09aec6a88ad0214a0ef26dcbcd Mon Sep 17 00:00:00 2001 From: Regela Date: Sat, 27 May 2023 22:27:00 +0300 Subject: [PATCH 3/3] Reformat --- .gitignore | 1 + demo/__init__.py | 2 +- demo/app.py | 6 +- demo/routes.py | 5 +- demo/templates/index.html | 141 +++++++++++++++++++------------------- demo/views/__init__.py | 2 +- demo/views/frontend.py | 3 +- entry.py | 9 +-- 8 files changed, 83 insertions(+), 86 deletions(-) diff --git a/.gitignore b/.gitignore index fa2cadf..2fe81d2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ +venv demo/__pycache__ demo/views/__pycache__ diff --git a/demo/__init__.py b/demo/__init__.py index b23f70e..819ccf0 100644 --- a/demo/__init__.py +++ b/demo/__init__.py @@ -1 +1 @@ -from .app import create_app \ No newline at end of file +from .app import create_app diff --git a/demo/app.py b/demo/app.py index 4fe0516..814e84e 100644 --- a/demo/app.py +++ b/demo/app.py @@ -7,7 +7,7 @@ import aiohttp_jinja2 async def create_app(): app = web.Application() aiohttp_jinja2.setup(app, - loader = jinja2.PackageLoader('demo', 'templates') - ) + loader=jinja2.PackageLoader('demo', 'templates') + ) setup_routes(app) - return app + return app diff --git a/demo/routes.py b/demo/routes.py index f333bef..d76ece0 100644 --- a/demo/routes.py +++ b/demo/routes.py @@ -1,6 +1,7 @@ from .views import frontend import aiohttp + def setup_routes(app): - app.router.add_routes([aiohttp.web.get('/', frontend.index), aiohttp.web.post('/button-clicked', frontend.button_clicked)]) - \ No newline at end of file + app.router.add_routes( + [aiohttp.web.get('/', frontend.index), aiohttp.web.post('/button-clicked', frontend.button_clicked)]) diff --git a/demo/templates/index.html b/demo/templates/index.html index a613686..73473d9 100644 --- a/demo/templates/index.html +++ b/demo/templates/index.html @@ -1,93 +1,96 @@ - - + + Знакомство с aiohttp - - -
-

Знакомство с aiohttp

-
+ + +
+

Знакомство с aiohttp

+
-
-

+
+ +
+

- -