The autoreload extension is already loaded. To reload it, use:
%reload_ext autoreload
The autoreload extension is already loaded. To reload it, use:
%reload_ext autoreload
{'firstname': 'Jane',
'lastname': 'Smith',
'phone': '555-5678',
'email': 'jane.smith@example.com',
'id': 1}
<!doctype html>
<html>
<head>
<title>Contact.App</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css">
<script src="https://unpkg.com/htmx.org@2.0.1"></script>
</head>
<body hx-boost="true">
<main class="container">
<h1> CONTACTS.APP</h1>
<h2> A demo contact application </h2>
<hr>
<article>
<h1>Alice Johnson </h1>
<div role="group">
<div>555-8765</div>
<div>alice.johnson@example.com</div>
</div>
<footer role="group">
<a href="/contacts" role="button">Back</a>
<a href="/contacts/2/edit" role="button">Edit</a>
</footer>
</article>
</main>
</body>
</html>
{'firstname': 'Alice',
'lastname': 'Johnson',
'phone': '555-8765',
'email': 'alice.johnson@example.com',
'id': 2}
@app.route("/contacts/<int:id>/edit", methods=['GET', 'POST'])
def edit(id):
if request.method == 'GET':
c_dict = Contacts().get(id)
c = Contact()
c.from_contacts_dict(c_dict)
c.check_valid(duplicate_ok=True)
return render_template('edit.html', contact=c)
else:
c_dict = Contacts().get(id)
c = Contact()
c.from_contacts_dict(c_dict)
c.firstname = request.form['firstname']
c.lastname = request.form['lastname']
c.phone=request.form['phone']
c.email=request.form['email']
c.check_valid(duplicate_ok=True)
if c.commit(duplicate_ok=True):
flash("Updated Contract")
return redirect("/contacts/"+str(id))
else: return render_template('edit.html', contact=c)
@app.route("/contacts/new", methods=['POST'])
def contact_new():
c = Contact(firstname=request.form['firstname'],
lastname=request.form['lastname'],
phone=request.form['phone'],
email=request.form['email'])
c.check_valid(duplicate_ok=False)
if c.commit(duplicate_ok=False):
flash("New contract created")
return redirect("/contacts")
else:
print(c)
return render_template('new.html', contact=c)