diff --git a/.vscode/launch.json b/.vscode/launch.json
index 306f58e..9b8cd49 100644
--- a/.vscode/launch.json
+++ b/.vscode/launch.json
@@ -11,6 +11,22 @@
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": true
+ },
+ {
+ "name": "Python: Flask",
+ "type": "python",
+ "request": "launch",
+ "module": "flask",
+ "env": {
+ "FLASK_APP": "app.py",
+ "FLASK_ENV": "development"
+ },
+ "args": [
+ "run",
+ "--no-debugger"
+ ],
+ "jinja": true,
+ "justMyCode": true
}
]
}
\ No newline at end of file
diff --git a/app.py b/app.py
new file mode 100644
index 0000000..9bba879
--- /dev/null
+++ b/app.py
@@ -0,0 +1,89 @@
+from flask import Flask
+from datetime import datetime
+from flask import render_template
+from flask import request
+
+app = Flask(__name__)
+
+@app.route("/")
+def index():
+ now = datetime.now()
+ user = {'username': 'Анатолий'}
+ if now.hour > 5 and now.hour <= 12:
+ time_of_day = "morning"
+ elif now.hour > 12 and now.hour <= 17:
+ time_of_day = "day"
+ elif now.hour > 17 and now.hour <= 23:
+ time_of_day = "evening"
+ else:
+ time_of_day = "night"
+
+ items = ["один","два", "три", "четыре", "пять" ]
+
+ return render_template('index.html', title='Home', user = user, time_of_day = time_of_day, items = items)
+
+@app.route("/hello")
+def hello_world():
+ now = datetime.now()
+ return f"
Hello, World! {now}
"
+
+
+@app.route("/simp_calc")
+def simple():
+ a = request.args.get("a", default = 0, type = float)
+ b = request.args.get("b", default = 0, type = float)
+ return f" {a} + {b} = { a + b }
"
+
+
+@app.route("/styled")
+def hello_styled():
+ now = datetime.now()
+ return f"""
+ Заголовок
+ Hello, world!
+ Текущее время : {now}
+ """
+
+@app.route('/calc', methods=['GET', 'POST'])
+def calc():
+ a = request.form.get("a", default = 0, type = float)
+ b = request.form.get("b", default = 0, type = float)
+ print(a,b)
+ return render_template("calc.html", a = a, b = b, result = a + b)
+
+import cat
+
+cats = {
+
+ "vasya": cat.Cat("vasya", 3),
+ "barsik": cat.Cat("barsik", 4),
+ "murzik": cat.Cat("murzik", 1),
+}
+
+@app.route('/cats')
+def list_cats():
+ return render_template("cats.html", cats = cats)
+
+@app.route('/cats/')
+def fish(name):
+ cat = cats[name]
+ return render_template("cat.html", cat = cat)
+
+@app.route("/cats/new", methods=["GET", "POST"])
+def create_cat():
+ name = request.form.get("name",default="untitled")
+ age = request.form.get("age",default=0,type=float)
+
+ new_cat = cat.Cat(name, age)
+
+ cats[new_cat.name] = new_cat
+
+ return render_template("new_cat.html")
+
+from flask import jsonify
+@app.route("/api/cats")
+def api_cats():
+ result = []
+ for key, item in cats:
+ result.append(item.toJson())
+ return jsonify(result)
\ No newline at end of file
diff --git a/cat.py b/cat.py
new file mode 100644
index 0000000..f03b9e8
--- /dev/null
+++ b/cat.py
@@ -0,0 +1,5 @@
+class Cat:
+ def __init__(self, name, age, img = ""):
+ self.name = name
+ self.age = age
+ self.img = img
diff --git a/templates/base_cat.html b/templates/base_cat.html
new file mode 100644
index 0000000..8727275
--- /dev/null
+++ b/templates/base_cat.html
@@ -0,0 +1,8 @@
+
+
+ Cat
+
+
+ {% block main %}{% endblock %}
+
+
\ No newline at end of file
diff --git a/templates/calc.html b/templates/calc.html
new file mode 100644
index 0000000..e03abed
--- /dev/null
+++ b/templates/calc.html
@@ -0,0 +1,15 @@
+
+
+ Calculator
+
+
+ Calculator
+
+ Result = {{result}}
+
+
diff --git a/templates/cat.html b/templates/cat.html
new file mode 100644
index 0000000..1f8cd61
--- /dev/null
+++ b/templates/cat.html
@@ -0,0 +1,14 @@
+{% extends "base_cat.html" %}
+{% block main %}
+{{cat.name}}:
+
+ -
+ Возраст: {{ cat.age }}
+
+ {% if cat.img %}
+ -
+
+
+ {% endif %}
+
+{% endblock %}
\ No newline at end of file
diff --git a/templates/cats.html b/templates/cats.html
new file mode 100644
index 0000000..ea50a58
--- /dev/null
+++ b/templates/cats.html
@@ -0,0 +1,13 @@
+{% extends "base_cat.html" %}
+{% block main %}
+Котики:
+
+ {% for key, cat in cats.items() %}
+ -
+ {{cat.name }}
+
+ {% endfor %}
+
+Добавить
+
+{% endblock %}
\ No newline at end of file
diff --git a/templates/index.html b/templates/index.html
new file mode 100644
index 0000000..e07ba37
--- /dev/null
+++ b/templates/index.html
@@ -0,0 +1,21 @@
+
+
+ {{ title }} - Microblog
+
+
+ {% if time_of_day == "morning" %}
+ Доброе утро, {{ user.username }}!
+ {% elif time_of_day == "day" %}
+ добрый день, {{ user.username }}!
+ {% elif time_of_day == "evening" %}
+ Добрый вечер, {{ user.username }}!
+ {% elif time_of_day == "night" %}
+ Доброй ночи, {{ user.username }}!
+ {% endif %}
+
+ {% for element in items %}
+ - {{element}}
>
+ {% endfor %}
+
+
+
\ No newline at end of file
diff --git a/templates/new_cat.html b/templates/new_cat.html
new file mode 100644
index 0000000..05efb04
--- /dev/null
+++ b/templates/new_cat.html
@@ -0,0 +1,14 @@
+{% extends "base_cat.html" %}
+{% block main %}
+Котик:
+
+
+{% endblock %}
\ No newline at end of file
diff --git a/work.code-workspace b/work.code-workspace
index 183d6d0..ad6382f 100644
--- a/work.code-workspace
+++ b/work.code-workspace
@@ -16,5 +16,27 @@
"eamodio.gitlens",
"mhutchie.git-graph"
]
+ },
+ "launch": {
+ "version": "0.2.0",
+ "configurations": [
+
+ {
+ "name": "Python: Flask",
+ "type": "python",
+ "request": "launch",
+ "module": "flask",
+ "env": {
+ "FLASK_APP": "app.py",
+ "FLASK_ENV": "development"
+ },
+ "args": [
+ "run",
+ "--no-debugger"
+ ],
+ "jinja": true,
+ "justMyCode": true
+ }
+ ]
}
}
diff --git a/zachet.work.code-workspace b/zachet.work.code-workspace
new file mode 100644
index 0000000..ad6382f
--- /dev/null
+++ b/zachet.work.code-workspace
@@ -0,0 +1,42 @@
+{
+ "folders": [
+ {
+ "name": "Configs(root)",
+ "path": "."
+ }
+ ],
+ "settings": {
+ "files.exclude": {
+ "**/.git": true,
+ },
+ },
+ "extensions": {
+ "recommendations": [
+ "ms-python.python",
+ "eamodio.gitlens",
+ "mhutchie.git-graph"
+ ]
+ },
+ "launch": {
+ "version": "0.2.0",
+ "configurations": [
+
+ {
+ "name": "Python: Flask",
+ "type": "python",
+ "request": "launch",
+ "module": "flask",
+ "env": {
+ "FLASK_APP": "app.py",
+ "FLASK_ENV": "development"
+ },
+ "args": [
+ "run",
+ "--no-debugger"
+ ],
+ "jinja": true,
+ "justMyCode": true
+ }
+ ]
+ }
+}