Bladeren bron

add home page

weichen 4 jaren geleden
bovenliggende
commit
dc4cb491d2
2 gewijzigde bestanden met toevoegingen van 49 en 5 verwijderingen
  1. 7 2
      backstage/home/routes.py
  2. 42 3
      backstage/templates/home.html

+ 7 - 2
backstage/home/routes.py

@@ -1,9 +1,14 @@
-from flask import render_template, Blueprint
+from flask import render_template, Blueprint, request, redirect, url_for, flash
 import requests
+from collections import defaultdict
 
 home_app = Blueprint('home', __name__)
 
 
 @home_app.route('/backstage/home')
 def home():
-    return render_template('home.html')
+    response = requests.get('http://127.0.0.1:5000/api/home')
+    if response.status_code == 200:
+        return render_template('home.html',
+                               title='首頁',
+                               contents=response.json())

+ 42 - 3
backstage/templates/home.html

@@ -1,4 +1,43 @@
 {% extends "layout.html" %}
-{% block content %}
-    <h1>Home</h1>
-{% endblock content %}
+{% block main %}
+<h1>{{ title }}</h1>
+{% for content in contents %}
+  <form action="{{ url_for('home.update', section_class=content.sectionClass) }}" method="POST">
+  <table id="example" class="table table-striped table-bordered" cellspacing="0" width="60%">
+    <thead>
+      <tr>
+        <th>數量</th>
+        <th>類型</th>
+        <th>內容</th>
+        <th style="text-align:center;width:100px;">
+            <input class="btn btn-primary" type="submit" value="提交">
+        </th>
+      </tr>
+    </thead>
+    {% for key, value in content.items() %}
+      {% if key != 'sectionClass' %}
+        {% for data in value %}
+          <tbody>
+            <tr>
+              <td>{{ loop.index }}</td>
+              <td>{{ key }}</td>
+              <td>
+                <input name="{{ key }}-{{ loop.index }}" class="form-control form-control-lg" value="{{ data }}">
+              </td>
+              <td>
+                <div>
+                  <a class="btn btn-secondary btn-sm m-1" href="#">編輯</a>
+                  <form action="#" method="POST">
+                    <input class="btn btn-danger" type="submit" value="刪除">
+                  </form>
+                </div>
+              </td>
+            </tr>
+          </tbody>
+        {% endfor %}
+      {% endif %}
+    {% endfor %}
+  </table>
+</form>
+{% endfor %}
+{% endblock main %}