Kaynağa Gözat

add home update into route

weichen 4 yıl önce
ebeveyn
işleme
4476e584fc
1 değiştirilmiş dosya ile 20 ekleme ve 0 silme
  1. 20 0
      backstage/home/routes.py

+ 20 - 0
backstage/home/routes.py

@@ -12,3 +12,23 @@ def home():
         return render_template('home.html',
                                title='首頁',
                                contents=response.json())
+
+
+@home_app.route('/backstage/home/update', methods=['POST'])
+def update():
+    update_data = defaultdict(list)
+    for key, value in request.form.items():
+        element_type = key.split('-')[0]
+        if element_type == 'img':
+            value = eval(value)
+        else:
+            value = str(value)
+        update_data[element_type].append(value)
+    response = requests.post(
+        'http://127.0.0.1:5000/api/gen/home?section={}'.format(
+            request.args.get('section_class')), json=update_data)
+    if response.status_code == 200:
+        flash('修改成功', 'success')
+    else:
+        flash('修改失敗', 'danger')
+    return redirect(url_for('home.home'))