浏览代码

Add an admin page

jherve 1 年之前
父节点
当前提交
eab1fa8ada
共有 4 个文件被更改,包括 26 次插入3 次删除
  1. 9 0
      src/de_quoi_parle_le_monde/web.py
  2. 2 2
      static/style.css
  3. 13 0
      templates/admin/index.html
  4. 2 1
      templates/index.html

+ 9 - 0
src/de_quoi_parle_le_monde/web.py

@@ -3,6 +3,7 @@ from fastapi.responses import HTMLResponse
 from fastapi.staticfiles import StaticFiles
 from fastapi.templating import Jinja2Templates
 
+from de_quoi_parle_le_monde.medias import media_collection
 app = FastAPI()
 
 
@@ -14,3 +15,11 @@ templates = Jinja2Templates(directory="templates")
 @app.get("/", response_class=HTMLResponse)
 async def read_root(request: Request):
     return templates.TemplateResponse(request=request, name="index.html", context={})
+
+
+
+@app.get("/admin", response_class=HTMLResponse)
+async def admin_index(request: Request):
+    return templates.TemplateResponse(request=request, name="admin/index.html", context={
+        "collections": media_collection
+    })

+ 2 - 2
static/style.css

@@ -1,3 +1,3 @@
-h1 {
-    color: darkturquoise;
+.admin {
+    color: red;
 }

+ 13 - 0
templates/admin/index.html

@@ -0,0 +1,13 @@
+<html>
+<head>
+    <title>Hello</title>
+    <link href="{{ url_for('static', path='/style.css') }}" rel="stylesheet">
+</head>
+<body class="admin">
+    <h1>Main admin page</h1>
+
+    {% for name, coll in collections.items() %}
+        <h2>{{ name }}</h2>
+    {% endfor %}
+</body>
+</html>

+ 2 - 1
templates/index.html

@@ -4,6 +4,7 @@
     <link href="{{ url_for('static', path='/style.css') }}" rel="stylesheet">
 </head>
 <body>
+    <a href="{{ url_for('admin_index') }}">Admin page</a>
     <h1>Hello World !</h1>
 </body>
-</html>
+</html>