'flask'
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
from flask import Flask, render_template, request
|
||||
from datetime import datetime
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
logs = []
|
||||
|
||||
@app.route("/")
|
||||
def home():
|
||||
return render_template("index.html")
|
||||
|
||||
|
||||
@app.route("/login", methods=["POST"])
|
||||
def login():
|
||||
username = request.form.get("username", "")
|
||||
password = request.form.get("password", "")
|
||||
|
||||
logs.append({
|
||||
"time": datetime.now().strftime("%H:%M:%S"),
|
||||
"type": "Login",
|
||||
"username": username,
|
||||
"password": password
|
||||
})
|
||||
|
||||
return render_template(
|
||||
"result.html",
|
||||
title="Login",
|
||||
message="Demo login received. (No authentication performed.)",
|
||||
data={"Username": username}
|
||||
)
|
||||
|
||||
|
||||
@app.route("/search")
|
||||
def search():
|
||||
q = request.args.get("q", "")
|
||||
|
||||
logs.append({
|
||||
"time": datetime.now().strftime("%H:%M:%S"),
|
||||
"type": "Search",
|
||||
"query": q
|
||||
})
|
||||
|
||||
return render_template(
|
||||
"result.html",
|
||||
title="Search",
|
||||
message="Search request received.",
|
||||
data={"Query": q}
|
||||
)
|
||||
|
||||
|
||||
@app.route("/contact", methods=["POST"])
|
||||
def contact():
|
||||
name = request.form.get("name", "")
|
||||
email = request.form.get("email", "")
|
||||
message = request.form.get("message", "")
|
||||
|
||||
logs.append({
|
||||
"time": datetime.now().strftime("%H:%M:%S"),
|
||||
"type": "Contact",
|
||||
"name": name,
|
||||
"email": email
|
||||
})
|
||||
|
||||
return render_template(
|
||||
"result.html",
|
||||
title="Contact",
|
||||
message="Contact form submitted.",
|
||||
data={
|
||||
"Name": name,
|
||||
"Email": email,
|
||||
"Message": message
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@app.route("/logs")
|
||||
def view_logs():
|
||||
html = """
|
||||
<h2>Application Logs</h2>
|
||||
<table border=1 cellpadding=8>
|
||||
<tr>
|
||||
<th>Time</th>
|
||||
<th>Type</th>
|
||||
<th>Details</th>
|
||||
</tr>
|
||||
"""
|
||||
|
||||
for log in reversed(logs):
|
||||
html += f"""
|
||||
<tr>
|
||||
<td>{log['time']}</td>
|
||||
<td>{log['type']}</td>
|
||||
<td>{log}</td>
|
||||
</tr>
|
||||
"""
|
||||
|
||||
html += "</table>"
|
||||
return html
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host="0.0.0.0", port=5000, debug=True)
|
||||
Reference in New Issue
Block a user