Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -686,7 +686,62 @@ def save_db():
|
|
686 |
|
687 |
|
688 |
|
689 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
690 |
|
691 |
|
692 |
|
|
|
686 |
|
687 |
|
688 |
|
689 |
+
@app.route('/contacts')
|
690 |
+
def show_contacts():
|
691 |
+
try:
|
692 |
+
conn = sqlite3.connect('data.db')
|
693 |
+
cursor = conn.cursor()
|
694 |
+
cursor.execute('SELECT name, phone, email FROM contacts')
|
695 |
+
contacts = cursor.fetchall()
|
696 |
+
conn.close()
|
697 |
+
|
698 |
+
# HTML-шаблон для отображения таблицы
|
699 |
+
html = '''
|
700 |
+
<!doctype html>
|
701 |
+
<html lang="en">
|
702 |
+
<head>
|
703 |
+
<meta charset="utf-8">
|
704 |
+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
705 |
+
<title>Contacts</title>
|
706 |
+
<style>
|
707 |
+
table {
|
708 |
+
width: 70%;
|
709 |
+
border-collapse: collapse;
|
710 |
+
}
|
711 |
+
th, td {
|
712 |
+
border: 1px solid black;
|
713 |
+
padding: 8px;
|
714 |
+
text-align: left;
|
715 |
+
}
|
716 |
+
th {
|
717 |
+
background-color: #f2f2f2;
|
718 |
+
}
|
719 |
+
</style>
|
720 |
+
</head>
|
721 |
+
<body>
|
722 |
+
<h1>Contacts</h1>
|
723 |
+
<table>
|
724 |
+
<tr>
|
725 |
+
<th>Name</th>
|
726 |
+
<th>Phone</th>
|
727 |
+
<th>Email</th>
|
728 |
+
</tr>
|
729 |
+
{% for contact in contacts %}
|
730 |
+
<tr>
|
731 |
+
<td>{{ contact[0] }}</td>
|
732 |
+
<td>{{ contact[1] }}</td>
|
733 |
+
<td>{{ contact[2] }}</td>
|
734 |
+
</tr>
|
735 |
+
{% endfor %}
|
736 |
+
</table>
|
737 |
+
</body>
|
738 |
+
</html>
|
739 |
+
'''
|
740 |
+
|
741 |
+
return render_template_string(html, contacts=contacts)
|
742 |
+
except Exception as e:
|
743 |
+
print(f"Error showing contacts: {e}")
|
744 |
+
return "Internal Server Error", 500
|
745 |
|
746 |
|
747 |
|