create route function +create.html

master
grgr 2 years ago
parent 4da31e0699
commit 2b632ff905

Binary file not shown.

@ -68,20 +68,14 @@ def home():
return render_template('home.html', categories=categories)
# @app.route("/add", methods=['GET', 'POST'])
# def create():
# # the goal here is to choose from a list of parameters what you want to add
# # 1- ogni blocco del form dovrebbe essere una tabella a parte
# if request.method == 'POST':
# title = request.form.get('title')
# author = request.form.get('author')
# description = request.form.get('description')
# add_book(author, title, description)
# # if author:
# # return url_for('add_new_author')
# return redirect(url_for('home'))
# return render_template('add_new.html')
@app.route("/add/", methods=['GET', 'POST'])
def create():
conn = get_db_connection()
categories = conn.execute('SELECT title FROM categories;').fetchall()
conn.close()
return render_template('create.html', categories=categories)
# app.run(port=3148)

@ -1,16 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>library</title>
</head>
<body>
<!-- <form method="POST" enctype="multipart/form-data">
<input type="text" name="author" placeholder="Author"/>
<input type="text" name="title" placeholder="Title"/>
<textarea name="description" cols="30" rows="10" placeholder="description"></textarea>
<input type="submit" value="Add" />
</form> -->
<div id="panel-container"></div>
</body>
</html>

@ -7,7 +7,7 @@
<!-- <script src="{{url_for('static', filename='addnew_panel.js')}}"></script> -->
</head>
<body>
<!--{# <a class="nav-link" href="{{ url_for('create') }}">New</a> #}-->
<a class="nav-link" href="{{ url_for('create') }}">New</a>
{% block content %} {% endblock %}
</body>
</html>

@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>library</title>
</head>
<body>
<select class="form-control" name="cat">
{% for cat in categories %}
{% if cat['title'] == request.form['cat'] %}
<option value="{{ request.form['cat'] }}" selected>
{{ request.form['cat'] }}
</option>
{% else %}
<option value="{{ cat['title'] }}">
{{ cat['title'] }}
</option>
{% endif %}
{% endfor %}
</select>
<div id="panel-container"></div>
</body>
</html>
Loading…
Cancel
Save