diff --git a/app.py b/app.py old mode 100644 new mode 100755 index a794957..03dba53 --- a/app.py +++ b/app.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 from flask import Flask, request, jsonify, render_template app = Flask(__name__) diff --git a/backend.py b/backend.py deleted file mode 100644 index 0631dbb..0000000 --- a/backend.py +++ /dev/null @@ -1,19 +0,0 @@ -def calculate(height, weight): - result = weight / (height ** 2) - return round(result, 2) - -def user_input_check(height, weight): - # Проверка, что введённые значения — числа - if not (height.replace('.', '', 1).isdigit() and weight.replace('.', '', 1).isdigit()): - return "Ошибка: введите корректные числовые значения." - - height = float(height) - weight = float(weight) - - if height <= 0 or height > 3: - return "Ошибка ввода роста. Рост должен быть больше 0 и не превышать 3 метра." - - if weight <= 0 or weight > 200: - return "Ошибка ввода веса. Вес должен быть больше 0 и не превышать 200 кг." - - return None # Успешная проверка \ No newline at end of file diff --git a/static/script.js b/static/script.js new file mode 100644 index 0000000..7c2e223 --- /dev/null +++ b/static/script.js @@ -0,0 +1,30 @@ +document.getElementById('bmi-form').addEventListener('submit', function(e) { + e.preventDefault(); + + const height = document.getElementById('height').value; + const weight = document.getElementById('weight').value; + const resultDiv = document.getElementById('result'); + + fetch('/calculate', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ height, weight }) + }) + .then(response => response.json()) + .then(data => { + if (data.error) { + resultDiv.style.display = 'block'; + resultDiv.style.color = '#cc0000'; + resultDiv.textContent = data.error; + } else { + resultDiv.style.display = 'block'; + resultDiv.style.color = '#003366'; + resultDiv.textContent = `Ваш BMI: ${data.bmi}`; + } + }) + .catch(() => { + resultDiv.style.display = 'block'; + resultDiv.textContent = 'Ошибка соединения с сервером.'; + resultDiv.style.color = '#cc0000'; + }); +}); \ No newline at end of file diff --git a/styles.css b/static/style.css similarity index 100% rename from styles.css rename to static/style.css diff --git a/index.html b/templates/index.html similarity index 93% rename from index.html rename to templates/index.html index 155c056..a7d062d 100644 --- a/index.html +++ b/templates/index.html @@ -5,7 +5,7 @@