Merge remote-tracking branch 'origin/develope' into develope

# Conflicts:
#	demo/routes.py
#	demo/views/frontend.py
#	entry.py
kirill 2 years ago
commit 1b2592ed32
  1. 1
      .gitignore
  2. 2
      demo/app.py
  3. 2
      demo/routes.py
  4. 27
      demo/templates/index.html
  5. 6
      demo/views/frontend.py
  6. 2
      requirements.txt

1
.gitignore vendored

@ -1,2 +1,3 @@
venv
demo/__pycache__ demo/__pycache__
demo/views/__pycache__ demo/views/__pycache__

@ -7,7 +7,7 @@ import aiohttp_jinja2
async def create_app(): async def create_app():
app = web.Application() app = web.Application()
aiohttp_jinja2.setup(app, aiohttp_jinja2.setup(app,
loader = jinja2.PackageLoader('demo', 'templates') loader=jinja2.PackageLoader('demo', 'templates')
) )
setup_routes(app) setup_routes(app)
return app return app

@ -2,5 +2,5 @@ from .views import frontend
import aiohttp import aiohttp
def setup_routes(app): def setup_routes(app):
app.router.add_routes([aiohttp.web.get('/', frontend.index), aiohttp.web.post('/submit', frontend.button_clicked)]) app.router.add_routes([aiohttp.web.get('/', frontend.index), aiohttp.web.post('/button-clicked', frontend.button_clicked)])

@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8"/>
<title>Знакомство с aiohttp</title> <title>Знакомство с aiohttp</title>
<style> <style>
html { html {
@ -10,7 +10,7 @@
body { body {
min-height: 100vh; min-height: 100vh;
background: linear-gradient(90deg, rgba(2,0,36,1) 0%, rgba(9,9,121,1) 35%, rgba(0,212,255,1) 100%) background: linear-gradient(90deg, rgba(2, 0, 36, 1) 0%, rgba(9, 9, 121, 1) 35%, rgba(0, 212, 255, 1) 100%)
} }
h1 { h1 {
@ -62,6 +62,7 @@
-moz-box-shadow: 0 5px 5px 0 rgba(0, 0, 0, 0.5); -moz-box-shadow: 0 5px 5px 0 rgba(0, 0, 0, 0.5);
box-shadow: 0 5px 5px 0 rgba(0, 0, 0, 0.5); box-shadow: 0 5px 5px 0 rgba(0, 0, 0, 0.5);
} }
#myResult { #myResult {
text-align: center; text-align: center;
color: white; color: white;
@ -69,25 +70,27 @@
} }
</style> </style>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head> </head>
<body> <body>
<div> <div>
<h1>Знакомство с aiohttp</h1> <h1>Знакомство с aiohttp</h1>
<div id="root"> <div id="root">
<div class="form"> <div class="form">
<div class="form__button"><button id='myButton'>Отправить</button></div> <div class="form__button">
<button id='myButton'>Отправить</button>
</div>
<p id="myResult"></p> <p id="myResult"></p>
</div> </div>
</div> </div>
</body> </body>
<script> <script>
$(document).ready(function() { $(document).ready(function () {
$("#myButton").click(function() { $("#myButton").click(function () {
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: "/button-clicked", url: "/button-clicked",
dataType: "json", dataType: "json",
success: function(response) { success: function (response) {
$("#myResult").text(response.result); $("#myResult").text(response.result);
} }
}); });

@ -10,8 +10,4 @@ async def index(request):
async def button_clicked(request): async def button_clicked(request):
data = await request.post() return aiohttp.web.json_response({'result':'Button was clicked'})
text = data.get('text')
response_text = f'Вы ввели: {text}'
print(response_text)
return aiohttp.web.Response(text=response_text)

@ -0,0 +1,2 @@
aiohttp~=3.8.4
Jinja2~=3.1.2
Loading…
Cancel
Save