From c5594f6da01e35b999a3c2955065f44cdb49cae8 Mon Sep 17 00:00:00 2001 From: grgr Date: Fri, 30 Sep 2022 17:12:44 +0200 Subject: [PATCH] form but it doesn't work --- app.py | 20 ++++++++++++++++++-- templates/base.html | 14 +++++++++++++- templates/create.html | 34 +++++++++++++++++++++++----------- 3 files changed, 54 insertions(+), 14 deletions(-) diff --git a/app.py b/app.py index 3e29b43..dcd5151 100644 --- a/app.py +++ b/app.py @@ -5,7 +5,7 @@ from itertools import groupby # to handle complex iterations import os import sqlite3 -from flask import Flask, render_template, url_for, request, redirect +from flask import Flask, render_template, url_for, request, redirect, flash # ----- functions ----- # @@ -72,9 +72,25 @@ def home(): def create(): conn = get_db_connection() + if request.method == 'POST': + content = request.form['content'] + cat_title = request.form['cat'] + + if not content: + flash('plz write a content!') + return redirect(url_for('home')) + + cat_id = conn.execute('SELECT id FROM categories WHERE title = (?);', + (cat_title,)).fetchone()['id'] + conn.execute('INSERT INTO cards (content, category_id) VALUES (?,?)', + (content, cat_title)) + conn.commit() + conn.close() + return redirect(url_for('home')) + categories = conn.execute('SELECT title FROM categories;').fetchall() + conn.close() - return render_template('create.html', categories=categories) diff --git a/templates/base.html b/templates/base.html index de535cf..667a107 100644 --- a/templates/base.html +++ b/templates/base.html @@ -7,7 +7,19 @@ - New + + + {% for message in get_flashed_messages() %} +
{{ message }}
+ {% endfor %} {% block content %} {% endblock %} diff --git a/templates/create.html b/templates/create.html index b969f7e..b20fe68 100644 --- a/templates/create.html +++ b/templates/create.html @@ -1,11 +1,19 @@ - - - - - library - - - + + +
+ + -
- - +
+
+ +
+ +{% endblock %} +