Compare commits
4 Commits
929bd0ca02
...
2c6dceee3e
Author | SHA1 | Date |
---|---|---|
|
2c6dceee3e | 2 years ago |
|
25cd1944e1 | 2 years ago |
|
e46f411734 | 2 years ago |
|
76b970dac6 | 2 years ago |
@ -0,0 +1,3 @@ |
||||
venv |
||||
demo/__pycache__ |
||||
demo/views/__pycache__ |
@ -0,0 +1 @@ |
||||
from .app import create_app |
@ -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 |
@ -0,0 +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)]) |
@ -0,0 +1,100 @@ |
||||
<!DOCTYPE html> |
||||
<html lang="en"> |
||||
<head> |
||||
<meta charset="UTF-8"/> |
||||
<title>Знакомство с aiohttp</title> |
||||
<style> |
||||
html { |
||||
font-family: Verdana, "sans-serif"; |
||||
} |
||||
|
||||
body { |
||||
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%) |
||||
} |
||||
|
||||
h1 { |
||||
text-align: center; |
||||
color: white; |
||||
text-shadow: 0 2px 5px rgba(150, 150, 150, 0.8); |
||||
} |
||||
|
||||
#root { |
||||
display: flex; |
||||
flex-direction: column; |
||||
align-items: center; |
||||
} |
||||
|
||||
|
||||
.form { |
||||
width: 70%; |
||||
margin-bottom: 20px; |
||||
} |
||||
|
||||
.form__button { |
||||
text-align: center; |
||||
margin-top: 10px; |
||||
background-color: white; |
||||
cursor: pointer; |
||||
} |
||||
|
||||
#myButton { |
||||
box-sizing: border-box; |
||||
width: 100%; |
||||
font-size: 18px; |
||||
outline: none; |
||||
border: none; |
||||
padding: 20px; |
||||
border-radius: 5px; |
||||
-webkit-transition: 0.3s; |
||||
-moz-transition: 0.3s; |
||||
transition: 0.3s; |
||||
-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); |
||||
box-shadow: 0px 5px 5px 0px rgba(0, 0, 0, 0.1); |
||||
} |
||||
|
||||
#myButton:hover { |
||||
-webkit-transition: 0.3s; |
||||
-moz-transition: 0.3s; |
||||
transition: 0.3s; |
||||
-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); |
||||
box-shadow: 0 5px 5px 0 rgba(0, 0, 0, 0.5); |
||||
} |
||||
|
||||
#myResult { |
||||
text-align: center; |
||||
color: white; |
||||
text-shadow: 0 2px 5px rgba(150, 150, 150, 0.8); |
||||
} |
||||
</style> |
||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> |
||||
</head> |
||||
<body> |
||||
<div> |
||||
<h1>Знакомство с aiohttp</h1> |
||||
<div id="root"> |
||||
<div class="form"> |
||||
<div class="form__button"> |
||||
<button id='myButton'>Отправить</button> |
||||
</div> |
||||
<p id="myResult"></p> |
||||
</div> |
||||
</div> |
||||
</body> |
||||
<script> |
||||
$(document).ready(function () { |
||||
$("#myButton").click(function () { |
||||
$.ajax({ |
||||
type: "POST", |
||||
url: "/button-clicked", |
||||
dataType: "json", |
||||
success: function (response) { |
||||
$("#myResult").text(response.result); |
||||
} |
||||
}); |
||||
}); |
||||
}); |
||||
</script> |
||||
</html> |
@ -0,0 +1 @@ |
||||
from . import frontend |
@ -0,0 +1,12 @@ |
||||
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'}) |
@ -0,0 +1,7 @@ |
||||
import aiohttp |
||||
from demo import create_app |
||||
|
||||
app = create_app() |
||||
|
||||
if __name__ == '__main__': |
||||
aiohttp.web.run_app(app) |
@ -0,0 +1,2 @@ |
||||
aiohttp~=3.8.4 |
||||
Jinja2~=3.1.2 |
Loading…
Reference in new issue