This repository has been archived on 2024-10-24. You can view files and clone it, but cannot push or open issues or pull requests.
NG_2022_Stanislav_Mykhailenko/Lesson_5/Task 3/webserver.py

28 lines
698 B
Python
Raw Permalink Normal View History

# Lesson 5 Task 3: web blog
# Author: Stanislav Mykhailenko
# License: Unlicense
2022-12-21 20:53:09 +00:00
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)