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