Update app.py
Browse files
app.py
CHANGED
@@ -7,7 +7,7 @@ DB_FILE = 'data.json'
|
|
7 |
|
8 |
def initialize_db():
|
9 |
try:
|
10 |
-
with open(DB_FILE, 'w') as f:
|
11 |
json.dump([], f)
|
12 |
print(f"Файл {DB_FILE} успешно создан.")
|
13 |
except Exception as e:
|
@@ -17,7 +17,7 @@ def load_products():
|
|
17 |
if not os.path.exists(DB_FILE):
|
18 |
initialize_db()
|
19 |
try:
|
20 |
-
with open(DB_FILE, 'r') as f:
|
21 |
products = json.load(f)
|
22 |
print(f"Данные успешно загружены из {DB_FILE}: {products}")
|
23 |
return products
|
@@ -27,7 +27,7 @@ def load_products():
|
|
27 |
|
28 |
def save_products(products):
|
29 |
try:
|
30 |
-
with open(DB_FILE, 'w') as f:
|
31 |
json.dump(products, f, indent=4)
|
32 |
print(f"Данные успешно сохранены в {DB_FILE}: {products}")
|
33 |
except Exception as e:
|
@@ -64,6 +64,7 @@ a {{ margin-right: 15px; text-decoration: none; color: #333; }}
|
|
64 |
@app.route('/')
|
65 |
def catalog():
|
66 |
products = load_products()
|
|
|
67 |
if not products:
|
68 |
return html_wrapper('<div class="header">Каталог товаров пуст</div>')
|
69 |
products_html = ''.join([
|
@@ -83,12 +84,13 @@ def catalog():
|
|
83 |
def admin():
|
84 |
if request.method == 'POST':
|
85 |
products = load_products()
|
|
|
86 |
|
87 |
try:
|
88 |
new_product = {
|
89 |
'name': request.form['name'],
|
90 |
'description': request.form['description'],
|
91 |
-
'price': float(request.form['price'])
|
92 |
}
|
93 |
products.append(new_product)
|
94 |
save_products(products)
|
|
|
7 |
|
8 |
def initialize_db():
|
9 |
try:
|
10 |
+
with open(DB_FILE, 'w', encoding='utf-8') as f:
|
11 |
json.dump([], f)
|
12 |
print(f"Файл {DB_FILE} успешно создан.")
|
13 |
except Exception as e:
|
|
|
17 |
if not os.path.exists(DB_FILE):
|
18 |
initialize_db()
|
19 |
try:
|
20 |
+
with open(DB_FILE, 'r', encoding='utf-8') as f:
|
21 |
products = json.load(f)
|
22 |
print(f"Данные успешно загружены из {DB_FILE}: {products}")
|
23 |
return products
|
|
|
27 |
|
28 |
def save_products(products):
|
29 |
try:
|
30 |
+
with open(DB_FILE, 'w', encoding='utf-8') as f:
|
31 |
json.dump(products, f, indent=4)
|
32 |
print(f"Данные успешно сохранены в {DB_FILE}: {products}")
|
33 |
except Exception as e:
|
|
|
64 |
@app.route('/')
|
65 |
def catalog():
|
66 |
products = load_products()
|
67 |
+
print(f"Загруженные товары: {products}") # Отладочное сообщение
|
68 |
if not products:
|
69 |
return html_wrapper('<div class="header">Каталог товаров пуст</div>')
|
70 |
products_html = ''.join([
|
|
|
84 |
def admin():
|
85 |
if request.method == 'POST':
|
86 |
products = load_products()
|
87 |
+
print(f"Текущие товары: {products}") # Отладочное сообщение
|
88 |
|
89 |
try:
|
90 |
new_product = {
|
91 |
'name': request.form['name'],
|
92 |
'description': request.form['description'],
|
93 |
+
'price': float(request.form['price'])
|
94 |
}
|
95 |
products.append(new_product)
|
96 |
save_products(products)
|