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. 4
      demo/app.py
  3. 2
      demo/routes.py
  4. 141
      demo/templates/index.html
  5. 6
      demo/views/frontend.py
  6. 2
      entry.py
  7. 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,93 +1,96 @@
<!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 {
font-family: Verdana, "sans-serif"; font-family: Verdana, "sans-serif";
} }
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 {
text-align: center; text-align: center;
color: white; color: white;
text-shadow: 0 2px 5px rgba(150, 150, 150, 0.8); text-shadow: 0 2px 5px rgba(150, 150, 150, 0.8);
} }
#root { #root {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
} }
.form { .form {
width: 70%; width: 70%;
margin-bottom: 20px; margin-bottom: 20px;
} }
.form__button { .form__button {
text-align: center; text-align: center;
margin-top: 10px; margin-top: 10px;
background-color: white; background-color: white;
cursor: pointer; cursor: pointer;
} }
#myButton { #myButton {
box-sizing: border-box; box-sizing: border-box;
width: 100%; width: 100%;
font-size: 18px; font-size: 18px;
outline: none; outline: none;
border: none; border: none;
padding: 20px; padding: 20px;
border-radius: 5px; border-radius: 5px;
-webkit-transition: 0.3s; -webkit-transition: 0.3s;
-moz-transition: 0.3s; -moz-transition: 0.3s;
transition: 0.3s; transition: 0.3s;
-webkit-box-shadow: 0px 5px 5px 0px rgba(0, 0, 0, 0.1); -webkit-box-shadow: 0px 5px 5px 0px rgba(0, 0, 0, 0.1);
-moz-box-shadow: 0px 5px 5px 0px rgba(0, 0, 0, 0.1); -moz-box-shadow: 0px 5px 5px 0px rgba(0, 0, 0, 0.1);
box-shadow: 0px 5px 5px 0px rgba(0, 0, 0, 0.1); box-shadow: 0px 5px 5px 0px rgba(0, 0, 0, 0.1);
} }
#myButton:hover { #myButton:hover {
-webkit-transition: 0.3s; -webkit-transition: 0.3s;
-moz-transition: 0.3s; -moz-transition: 0.3s;
transition: 0.3s; transition: 0.3s;
-webkit-box-shadow: 0 5px 5px 0 rgba(0, 0, 0, 0.5); -webkit-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); -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 {
text-align: center; #myResult {
color: white; text-align: center;
text-shadow: 0 2px 5px rgba(150, 150, 150, 0.8); color: white;
} text-shadow: 0 2px 5px rgba(150, 150, 150, 0.8);
}
</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">
<p id="myResult"></p> <button id='myButton'>Отправить</button>
</div>
<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)

@ -11,4 +11,4 @@ app = create_app()
if __name__ == '__main__': if __name__ == '__main__':
aiohttp.web.run_app(app) aiohttp.web.run_app(app)

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