Add Lesson 5 Task 3
This commit is contained in:
parent
507ad1caff
commit
a6623ce880
5 changed files with 71 additions and 2 deletions
1
Lesson_5/Task 3/.gitignore
vendored
Normal file
1
Lesson_5/Task 3/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
articles.txt
|
15
Lesson_5/Task 3/templates/editor.html
Normal file
15
Lesson_5/Task 3/templates/editor.html
Normal 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>
|
12
Lesson_5/Task 3/templates/index.html
Normal file
12
Lesson_5/Task 3/templates/index.html
Normal 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>
|
23
Lesson_5/Task 3/webserver.py
Normal file
23
Lesson_5/Task 3/webserver.py
Normal 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)
|
22
README.md
22
README.md
|
@ -17,8 +17,26 @@ Checked means the task is Done.
|
||||||
### Lesson 2
|
### Lesson 2
|
||||||
|
|
||||||
- [ ] Task 1
|
- [ ] 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 2
|
||||||
- [ ] Task 3
|
- [ ] Task 3
|
||||||
- [ ] Task 4
|
- [ ] Task 4
|
||||||
- [ ] Task 5
|
|
||||||
- [ ] Task %*f#ncA0#>?
|
### Lesson 6
|
||||||
|
- [ ] Task 1
|
||||||
|
- [ ] Task 2
|
||||||
|
|
Reference in a new issue