-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathserver.py
57 lines (42 loc) · 1.21 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import uvicorn
from blacksheep.messages import Response
from blacksheep.server import Application
from blacksheep.server.responses import html
from piccoloexample import APP, create_schema, populate_data, set_engine
app = Application()
@app.route("/")
def home() -> Response:
return html(
"""
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>BlackSheep - mount example</title>
</head>
<body>
<h1>BlackSheep - mount example</h1>
<ol>
<li>Navigate to <a href="/admin">the Piccolo Admin login page</a></li>
<li>Sign in using (username: piccolo, password: piccolo123)</li>
<li>Read more about <a href="https://github.com/piccolo-orm/piccolo_admin">Piccolo Admin here</a></li>
</ol>
</body>
</html>
"""
)
app.mount("/admin", APP)
def configure():
engine = "sqlite"
persist = False
set_engine("sqlite")
create_schema(persist=persist)
if not persist:
populate_data(inflate=1, engine=engine)
@app.on_start
async def configure_sqlite(_):
configure()
if __name__ == "__main__":
configure()
uvicorn.run(app, host="127.0.0.1", port=44777, log_level="debug")