import os
import sys
import json
import uuid
import flask
from flask import Flask, render_template, request, redirect, url_for, session
initialize the flask app
app = Flask(name)
app.secret_key = os.environ.get('SECRET_KEY') or str(uuid.uuid4())
Login/Registration page
@app.route("/", methods=["GET", "POST"])
def login_registration():
if request.method == "POST":
Get the user input
name = request.form.get("name")
email = request.form.get("email")
bar_name = request.form.get("bar_name")
license_info = request.form.get("license_info")
# Store the user data in the session
session["user"] = {
"name": name,
"email": email,
"bar_name": bar_name,
"license_info": license_info
}
# Redirect to the homepage
return redirect(url_for("homepage"))
return render_template("login_registration.html")
Homepage
@app.route("/homepage")
def homepage():
user = session.get("user")
if not user:
If user is not logged in, redirect to the login page
return redirect(url_for("login_registration"))
# Load the available merchandise from a JSON file
with open("merchandise.json") as f:
merchandise = json.load(f)
return render_template("homepage.html", user=user, merchandise=merchandise)
Product Catalog
@app.route("/catalog/")
def product_catalog(category):
user = session.get("user")
if not user:
If user is not logged in, redirect to the login page
return redirect(url_for("login_registration"))
# Load the available merchandise from a JSON file
with open("merchandise.json") as f:
merchandise = json.load(f)
# Filter the products by category
products = [p for p in merchandise if p["category"] == category]
return render_template("product_catalog.html", user=user, products=products)
Cart
@app.route("/cart", methods=["GET", "POST"])
def cart():
user = session.get("user")
if not user:
If user is not logged in, redirect to the login page
return redirect(url_for("login_registration"))
# Load the cart items from the session
cart_items = session.get("cart_items", [])
if request.method == "POST":
# Get the product ID and quantity from the form
product_id = request.form.get("product_id")
quantity = int(request.form.get("quantity"))
# Update the quantity of the item in the cart
item_found = False
for i, item in enumerate(cart_items):
if item
import required modules
import os import sys import json import uuid import flask from flask import Flask, render_template, request, redirect, url_for, session
initialize the flask app
app = Flask(name) app.secret_key = os.environ.get('SECRET_KEY') or str(uuid.uuid4())
Login/Registration page
@app.route("/", methods=["GET", "POST"]) def login_registration(): if request.method == "POST":
Get the user input
Homepage
@app.route("/homepage") def homepage(): user = session.get("user") if not user:
If user is not logged in, redirect to the login page
Product Catalog
@app.route("/catalog/")
def product_catalog(category):
user = session.get("user")
if not user:
If user is not logged in, redirect to the login page
Cart
@app.route("/cart", methods=["GET", "POST"]) def cart(): user = session.get("user") if not user:
If user is not logged in, redirect to the login page