Add Lesson 5 Task 3

This commit is contained in:
Stanislav Mykhailenko 2022-12-21 22:53:09 +02:00
parent 507ad1caff
commit a6623ce880
GPG key ID: 1E95E66A9C9D6A36
5 changed files with 71 additions and 2 deletions

1
Lesson_5/Task 3/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
articles.txt

View file

@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<title>Editor</title>
</head>
<body>
<form action="/process.html">
<label for="title">Title: </label><br>
<input type="text" id="title" name="title"><br>
<label for="text">Name: </label><br>
<textarea name="text" rows="5" cols="50" ></textarea><br>
<input type="submit" value="Submit">
</form>
</body>
</html>

View file

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>News</title>
</head>
<body>
<div>
{{contents|safe}}
</div>
<a href="/editor">Add</a>
</body>
</html>

View file

@ -0,0 +1,23 @@
from flask import Flask, render_template, redirect, request
from datetime import datetime
app = Flask("News")
@app.route('/')
def index():
with open("articles.txt", "r") as file:
data = file.read()
return render_template("index.html", contents=data)
@app.route('/editor')
def editor():
return render_template("editor.html")
@app.route('/process.html')
def process():
with open("articles.txt", "a") as file:
file.write("<h1>" + str(request.args.get('title')) + "</h1>\n<h4>" + str(datetime.now()) + "</h4>\n<h2>" + str(request.args.get('text')) + "</h2><hr>\n")
return redirect('/')
app.run(port=8080)

View file

@ -17,8 +17,26 @@ Checked means the task is Done.
### Lesson 2
- [ ] Task 1
- [x] Task 2
- [ ] Task 3
- [ ] Task 4
- [x] Task 5
- [ ] Task %*f#ncA0#>?
### Lesson 3
- [ ] Task 1
- [ ] Task 2
- [ ] Task 3
- [ ] Task K3F9#@%^&?
### Lesson 4
- [ ] Task 1
### Lesson 5
- [ ] Task 2
- [ ] Task 3
- [ ] Task 4
- [ ] Task 5
- [ ] Task %*f#ncA0#>?
### Lesson 6
- [ ] Task 1
- [ ] Task 2