Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Kucherova Ann/workshop3/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>404 page</title>
</head>
<body>
<h2> Not correct action value: {{action_value}} </h2>
</body>
</html>
Binary file added Kucherova Ann/workshop3/WorkShop2 Flask.pdf
Binary file not shown.
38 changes: 38 additions & 0 deletions Kucherova Ann/workshop3/all.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>all</title>
</head>
<body>
<table>
<tr>
<th>user_id</th>
<th>user_name</th>
<th>user_email</th>
</tr>
<tr>
<td>{{user.get("user_id")}}</td>
<td>{{user.get("user_name")}}</td>
<td>{{user.get("user_email")}}</td>
</tr>
</table>
<br/>
<table>
<tr>
<th>studio_id</th>
<th>studio_name</th>
<th>studio_email</th>
<th>studio_number</th>
<th>studio_address</th>
</tr>
<tr>
<td>{{studio.get("studio_id")}}</td>
<td>{{studio.get("studio_name")}}</td>
<td>{{studio.get("studio_email")}}</td>
<td>{{studio.get("studio_number")}}</td>
<td>{{studio.get("studio_address")}}</td>
</tr>
</table>
</body>
</html>
55 changes: 55 additions & 0 deletions Kucherova Ann/workshop3/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from flask import Flask, render_template, request, redirect, url_for

app = Flask(__name__)


@app.route('/api/<action>', methods=['GET'])
def apiget(action):
if action == "user":
return render_template("user.html", user=user_d)

elif action == "studio":
return render_template("studio.html", studio=studio_d)

elif action == "all":
return render_template("all.html", user=user_d, studio=studio_d)

else:
return render_template("404.html", user=user_d, studio=studio_d, action_value=action)

@app.route('/api/', methods=['POST'])
def apipost(action):
if request.form["action"] == '"user_apdate':
user_d["user_id"] = request.form["id"]
user_d["user_name"] = request.form["name"]
user_d["user_email"] = request.form["email"]

return redirect(url_for("apiget", action="all"))

if request.form["action"] == '"studio_apdate':
studio_d["studio_id"] = request.form["id"]
studio_d["studio_name"] = request.form["st_name"]
studio_d["studio_email"] = request.form["st_email"]
studio_d["studio_number"] = request.form["st_number"]
studio_d["studio_address"] = request.form["st_address"]

return redirect(url_for("apiget", action="all"))


if __name__ == '__main__':

user_d = {
"user_id": 1,
"user_name": "Ann",
"user_email": "ann@gmail.com"
}

studio_d = {
"studio_id": 3,
"studio_name": "Luckoutclub",
"studio_email": "luckout@gmail.com",
"studio_number": "099 123 1234",
"studio_address": "Heroiv dnipra 1"
}

app.run(debug=True)
16 changes: 16 additions & 0 deletions Kucherova Ann/workshop3/studio.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>studio</title>
</head>
<body>
<form action="/api" method="Post" id="studioform">
<p>Studio name: <input type = "text" name = "name" value="{{studio.get('studio_name')}}"/> </p>
<p>Studio email: <input type = "text" name = "email" value="{{studio.get('studio_email')}}"/> </p>
<p>Studio number: <input type = "text" name = "number" value="{{studio.get('studio_number')}}"/> </p>
<p>Studio address: <input type = "text" name = "address" value="{{studio.get('studio_address')}}"/> </p>
</form>
<button type="submit" form="studioform" name="action" value="user_update">Submit</button>
</body>
</html>
14 changes: 14 additions & 0 deletions Kucherova Ann/workshop3/user.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>user</title>
</head>
<body>
<form action="/api" method="Post" id="userform">
<p>Name: <input type = "text" name = "name" value="{{user.get('user_name')}}"/> </p>
<p>Email: <input type = "text" name = "email" value="{{user.get('user_email')}}"/> </p>
</form>
<button type="submit" form="userform" name="action" value="user_update">Submit</button>
</body>
</html>