form but it doesn't work

master
grgr 2 years ago
parent 2b632ff905
commit c5594f6da0

@ -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()
conn.close()
return render_template('create.html', categories=categories)

@ -7,7 +7,19 @@
<!-- <script src="{{url_for('static', filename='addnew_panel.js')}}"></script> -->
</head>
<body>
<a class="nav-link" href="{{ url_for('create') }}">New</a>
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="{{ url_for('create') }}">New</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="#">About</a>
</li>
</ul>
{% for message in get_flashed_messages() %}
<div class="alert alert-danger">{{ message }}</div>
{% endfor %}
{% block content %} {% endblock %}
</body>
</html>

@ -1,11 +1,19 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>library</title>
</head>
<body>
<select class="form-control" name="cat">
{% extends 'base.html' %}
{% block content %}
<h1>{% block title %} Create a New Item {% endblock %}</h1>
<form method="post">
<div class="form-group">
<label for="content">Content</label>
<input type="text" name="content"
placeholder="Todo content" class="form-control"
value="{{ request.form['content'] }}"></input>
</div>
<div class="form-group">
<label for="category">category/type</label>
<select class="form-control" name="category">
{% for cat in categories %}
{% if cat['title'] == request.form['cat'] %}
<option value="{{ request.form['cat'] }}" selected>
@ -18,6 +26,10 @@
{% endif %}
{% endfor %}
</select>
<div id="panel-container"></div>
</body>
</html>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
{% endblock %}

Loading…
Cancel
Save