From f4b5bc7c5016e5385059ba9f0ad2563812cb05be Mon Sep 17 00:00:00 2001 From: ondra Date: Wed, 13 Nov 2024 14:10:52 +0100 Subject: [PATCH] web --- web/app.py | 46 +++++++++++++++ web/static/style.css | 117 +++++++++++++++++++++++++++++++++++++++ web/templates/about.html | 18 ++++++ web/templates/home.html | 91 ++++++++++++++++++++++++++++++ 4 files changed, 272 insertions(+) create mode 100644 web/app.py create mode 100644 web/static/style.css create mode 100644 web/templates/about.html create mode 100644 web/templates/home.html diff --git a/web/app.py b/web/app.py new file mode 100644 index 0000000..625bf15 --- /dev/null +++ b/web/app.py @@ -0,0 +1,46 @@ +from flask import Flask, render_template, request, redirect, url_for +import logging +from datetime import datetime + +app = Flask(__name__) + +# Set up custom logging +logging.basicConfig(level=logging.DEBUG) + +# Remove werkzeug logs by setting its logger to a higher level (e.g., ERROR) +werkzeug_logger = logging.getLogger('werkzeug') +werkzeug_logger.setLevel(logging.ERROR) + +# Log client IP before each request +@app.before_request +def log_client_ip(): + # Get client IP address from X-Forwarded-For header or remote_addr + client_ip = request.headers.get('X-Forwarded-For', request.remote_addr) + client_ip = client_ip.split(',')[0] # Get the first IP if it's a forwarded request + +# Override werkzeug's default logging to show client IP in the access log +@app.after_request +def log_request(response): + client_ip = request.headers.get('X-Forwarded-For', request.remote_addr) + client_ip = client_ip.split(',')[0] # Get the first IP if it's a forwarded request + app.logger.info(f"{client_ip} - - [{request.date}] \"{request.method} {request.full_path} {request.environ.get('SERVER_PROTOCOL')}\" {response.status_code}") + return response + +@app.route('/') +def home(): + greeting = "Hello, Python!" + current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S') + return render_template('home.html', greeting=greeting, current_time=current_time) + +@app.route('/about') +def about(): + return render_template('about.html') + +# Always redirect back home +@app.errorhandler(404) +def default_page(e): + return redirect(url_for('home')) + + +if __name__ == "__main__": + app.run(debug=True, host="0.0.0.0", port=5005) diff --git a/web/static/style.css b/web/static/style.css new file mode 100644 index 0000000..cf2ddad --- /dev/null +++ b/web/static/style.css @@ -0,0 +1,117 @@ +body { + font-family: Arial, sans-serif; + margin: 0; + padding: 0; + background-color: #f4f4f4; + } + + header, footer { + background-color: #ccc; + padding: 10px; + text-align: center; + } + + .container { + width: 90%; + max-width: 1200px; + margin: 0 auto; + } + + .contact-info, .buttons { + display: flex; + justify-content: space-between; + padding: 10px 0; + } + + .navbar { + display: flex; + justify-content: space-around; + background-color: #ddd; + padding: 10px; + margin-bottom: 10px; + } + + .navbar a { + text-decoration: none; + color: black; + padding: 5px 15px; + } + + .content { + display: flex; + flex-wrap: wrap; + } + + .about, .map, .service-info, .photos { + box-sizing: border-box; + padding: 15px; + background-color: white; + margin: 10px; + border: 1px solid #ccc; + } + + .about, .map { + flex: 2 1 60%; + } + + .photos, .directions { + flex: 1 1 30%; + } + + .map { + text-align: center; + } + + .services { + margin: 20px 0; + padding: 15px; + background-color: white; + border: 1px solid #ccc; + } + + .service-list { + display: flex; + justify-content: space-around; + flex-wrap: wrap; + } + + .service-item { + flex: 1 1 200px; + text-align: center; + padding: 15px; + } + + .service-item img { + width: 100px; + height: auto; + } + + .footer { + background-color: #ccc; + display: flex; + justify-content: space-around; + padding: 20px; + flex-wrap: wrap; + } + + .footer div { + flex: 1 1 100px; + padding: 10px; + text-align: center; + } + + .reviews { + display: flex; + justify-content: space-around; + margin-top: 20px; + } + + .review-box { + width: 150px; + height: 80px; + background-color: #f9f9f9; + border: 1px solid #ccc; + padding: 10px; + text-align: center; + } + \ No newline at end of file diff --git a/web/templates/about.html b/web/templates/about.html new file mode 100644 index 0000000..0d4f01e --- /dev/null +++ b/web/templates/about.html @@ -0,0 +1,18 @@ + + + + + + About Us + + +

About Our Flask Application

+

This is a simple Flask application created to demonstrate how to render templates and create routes.

+

Flask is a micro web framework for Python. It is easy to use, lightweight, and flexible for creating web applications.

+ +

Our Mission

+

To provide an easy-to-understand tutorial for web development using Flask and Python!

+ +

Back to Home

+ + diff --git a/web/templates/home.html b/web/templates/home.html new file mode 100644 index 0000000..c8a5c95 --- /dev/null +++ b/web/templates/home.html @@ -0,0 +1,91 @@ + + + + + + Autoservis + + + + +
+
+

Autoservis

+
+ Kontakt: 123 123 123 + Otevírací doba: 9-18 hod + auto@servis.cz +
+
+ + +
+
+
+ + + +
+
+
+

O nás

+

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla consequat.

+
+
+

Fotografie autoservisu

+
+
+

+ +

+
+
+

Jak se k nám dostanete?

+

Lorem ipsum dolor sit amet, consectetur adipiscing elit.

+
+
+ +
+

Nabídka služeb

+
+
+ Car +

Oprava osobních vozidel

+
+
+ ATV +

Oprava čtyřkolek

+
+
+ Scooter +

Oprava skútrů

+
+
+ Motorcycle +

Oprava motorek

+
+
+
+ +
+
Recenze 1
+
Recenze 2
+
Recenze 3
+
Recenze 4
+
+
+ + + + +