RemoveWatermark Flask Practical
RemoveWatermark Flask Practical
PAGE
S.NO DATE PROGRAM NAME SIGNATURE
NO
01 Session Object
02 Alert Notification
04 Email Validator
06 Student Module
07 Staff Module
EX.NO: 01
DATE: SESSION OBJECTS
Aim:
procedure:
Step 1: Begin by importing the required modules from Flask: `Flask`,
`session`, `request`, `render_template`, `redirect`, and `url_for`.
Step 2: Create an instance of the Flask app by calling `Flask(__name__)`.
Set the `app.secret_key` to a string like `"super secret key"` to ensure that
the session is secure.
Step 3: Define the main route (`"/"`) using the `@app.route` decorator.
Allow this route to handle both `GET` and `POST` requests.
Step 4: Inside the view function for the main route, check the request
method. If it's a `POST` request, retrieve the username from the
submitted form data using `request.form["username"]`.
Step 5: Store the username in the session by setting `session["username"]
= username`, allowing the username to persist across different requests.
Step 6: After storing the username, use `render_template` to render the
`base.html` template, passing the `username` to the template so it
can be displayed on the webpage.
Step 7: If the request is a `GET`, render the `base.html` template without
passing the username (or simply render the page with a default
empty form).
Step 8: Define another route (`"/delete_session"`) using `@app.route` to
handle `POST` requests. This route is responsible for clearing the session
data.
Step 9: Inside this delete session route, use `session.pop("username",
None)` to remove the username from the session, then redirect the user
to the main page (`index`) using `redirect(url_for("index"))`.
Step 10: Finally, in the `if __name__ == "__main__"` block, run the Flask
application with `app.run(debug=True)` to enable debugging
and start the web server.
CODE:
app.py
from flask import Flask, session, request, render_template, redirect,
url_for
app = Flask(__name__)
app.secret_key = "super secret key" # set a secret key for the session
@app.route("/delete_session", methods=["POST"])
def delete_session():
session.pop("username", None)
return redirect(url_for("index"))
if __name__ == "__main__":
app.run(debug=True)
index.html
<!DOCTYPE html>
<html>
<head>
<title>Session Example</title>
</head>
<body>
<h1>Session Example</h1>
{% if username %}
<p>Welcome, {{ username }}!</p>
<form action="/delete_session" method="post">
<input type="submit" value="Delete Session">
</form>
{% else %}
<form action="/" method="post">
<label for="username">Enter your username:</label>
<input type="text" id="username" name="username">
<input type="submit" value="Set Username">
</form>
{% endif %}
</body>
</html>
Output:
Result:
Thus the above program has been executed successfully.
EX.NO: 02
DATE: ALERT NOTIFICATION
Aim:
The aim of this Flask application is to create a simple web form
that collects user input (name, class, and roll number), displays an alert
notification with the submitted information upon form submission, and
redirects back to the form.
Procedure:
Step 3: Define a route for the home page ("/") that supports both GET
and POST requests.
Step 5: If the request method is POST, retrieve the values of name, class,
and roll number from the submitted form.
Step 6: Use the flash function to create a flash message that includes the
retrieved input data.
Step 7: Redirect the user to the same route ("/") to display the input form
again.
Step 10: At the bottom of the HTML template, check for flashed
messages and use JavaScript to display an alert with the first message
when it exists.
CODE:
app.py
from flask import Flask, render_template, request, flash, redirect, url_for
app = Flask(__name__)
app.secret_key = "your_secret_key" # Needed for session management
if __name__ == "__main__":
app.run(debug=True)
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,
initial-scale=1.0">
<title>Flask Alert Example</title>
<script>
function showAlert(message) {
if (message) {
alert(message);
}
}
</script>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 20px;
}
h1 {
color: #333;
text-align: center;
}
form {
background: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
max-width: 400px;
margin: auto;
}
label {
font-weight: bold;
display: block;
margin-bottom: 5px;
}
input[type="text"] {
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
margin-bottom: 15px;
}
button {
background-color: #5cb85c;
color: white;
padding: 10px;
border: none;
border-radius: 4px;
cursor: pointer;
width: 100%;
font-size: 16px;
}
button:hover {
background-color: #4cae4c;
}
</style>
</head>
<body>
<h1>Input Form</h1>
<form method="POST">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required><br><br>
<label for="class">Class:</label>
<input type="text" id="class" name="class" required><br><br>
<button type="submit">Submit</button>
</form>
Output:
Result:
Thus the above program has been executed successfully.
EX.NO: 03
DATE: To-Do List Using CRUD
Aim:
To develop a Flask-based To-Do list application that allows users
to perform basic CRUD operations on tasks, providing functionality to
add, update, and delete tasks dynamically through a web interface.
procedure:
Step 1: Initialize the Flask application and create an empty list to store
tasks.
Step 2: Create a route for the index page ("/") that renders the
index.html template and passes the list of tasks.
Step 3: In the index.html file, create an HTML form to add new tasks
with a submit button, and display the current tasks as a list.
Step 4: Define the /add route to handle the POST request for adding
tasks. Retrieve the task from the form input and append it to the task list
if it's not empty.
Step 5: Redirect the user back to the index page after adding a task.
Step 6: In the index.html file, include forms next to each task to allow
updates and a delete button for removing tasks.
Step 8: After updating a task, redirect the user back to the index page to
display the updated list.
CODE:
app.py
from flask import Flask, render_template, request, redirect, url_for
app = Flask(__name__)
tasks = []
@app.route("/")
def index():
return render_template("index.html", tasks=tasks)
@app.route("/add", methods=["POST"])
def add_task():
task_content = request.form.get("task")
if task_content:
tasks.append(task_content)
return redirect(url_for("index"))
@app.route("/update/<int:task_id>", methods=["POST"])
def update_task(task_id):
new_content = request.form.get("task")
if new_content and 0 <= task_id < len(tasks):
tasks[task_id] = new_content
return redirect(url_for("index"))
@app.route("/delete/<int:task_id>")
def delete_task(task_id):
if 0 <= task_id < len(tasks):
tasks.pop(task_id)
return redirect(url_for("index"))
if __name__ == "__main__":
app.run(debug=True)
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,
initial-scale=1.0">
<title>Flask To-Do App</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 20px;
}
h1 {
text-align: center;
color: #333;
}
form {
display: flex;
justify-content: center;
}
input[type="text"] {
padding: 10px;
border: 2px solid #007BFF;
border-radius: 5px;
width: 300px;
transition: border-color 0.3s ease;
}
input[type="text"]:focus {
border-color: #0056b3;
outline: none;
}
button {
padding: 10px 15px;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
margin-left: 10px;
transition: background-color 0.3s ease, transform 0.3s ease;
}
button:hover {
transform: scale(1.05);
}
ul {
width: 40%;
margin-left: 30%;
list-style-type: none;
padding: 0;
}
li {
background-color: white;
margin-bottom: 5px;
padding: 15px;
border-radius: 5px;
display: flex;
justify-content: space-between;
align-items: center;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
a{
text-decoration: none;
color: white;
}
a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<h1>To-Do List</h1>
Result:
Thus the above program has been executed successfully.
EX.NO: 04
DATE: EMAIL VALIDATOR
Aim:
The aim of this Flask application is to validate user-provided email
addresses using regular expressions and provide feedback on the
validity of the email input. It also offers a simple API endpoint that
returns a greeting message in JSON format.
procedure:
Step 1: Import the necessary modules including Flask, render_template,
request, redirect, url_for, jsonify, and re.
Step 2: Initialize the Flask application by creating an instance of the
Flask class.
Step 3: Define a function is_valid_email(email) that takes an email
string as an input and validates it using a regular expression.
Step 4: Create a route for the index page ("/") that accepts both GET and
POST requests.
Step 5: Inside the index route, initialize variables for validation_result
and result_class to hold the validation message and CSS class
respectively.
Step 6: If the request method is POST, retrieve the email input from the
form.
Step 7: Call the is_valid_email(email) function to check if the email is
valid. If valid, set validation_result to indicate success and
assign "valid" to result_class; if invalid, set
validation_result to indicate failure and assign "invalid" to
result_class.
Step 8: Render the index.html template, passing in the
validation_result and result_class.
Step 9: Define an additional route for the API endpoint ("/api/greet")
that returns a JSON response with a greeting message.
Step 10: Run the Flask application in debug mode when the script is
executed directly.
CODE:
app.py
from flask import Flask, render_template, request, redirect, url_for,
jsonify
import re
app = Flask(__name__)
def is_valid_email(email):
# Simple regex for validating an Email
pattern = r"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$"
return re.match(pattern, email) is not None
@app.route("/api/greet")
def greet():
# Return a JSON response
return jsonify(message="Hello, API!", greet="vanakkam da mapla")
if __name__ == "__main__":
app.run(debug=True)
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,
initial-scale=1.0">
<title>Email Validator</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
color: #333;
margin: 0;
padding: 20px;
}
h1 {
text-align: center;
color: #4CAF50;
}
form {
background-color: white;
padding: 20px;
border-radius: 5px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
max-width: 400px;
margin: auto;
}
label {
display: block;
margin-bottom: 10px;
}
input[type="text"] {
width: calc(100% - 20px);
padding: 10px;
margin-bottom: 20px;
border: 1px solid #ccc;
border-radius: 5px;
}
button {
background-color: #4CAF50;
color: white;
border: none;
padding: 10px 15px;
border-radius: 5px;
cursor: pointer;
width: 100%;
}
button:hover {
background-color: #45a049;
}
h2 {
text-align: center;
font-weight: bold;
}
.valid {
color: green; /* Green for valid emails */
}
.invalid {
color: red; /* Red for invalid emails */
}
</style>
</head>
<body>
<h1>Email Validator</h1>
<form method="POST" action="/">
<label for="email">Enter your email:</label>
<input type="text" name="email" id="email" required>
<button type="submit">Validate</button>
</form>
{% if result %}
<h2 class="{{ result_class }}">{{ result }}</h2> <!-- Apply the CSS class
here -->
{% endif %}
</body>
</html>
output:
For Valid Mail Id’s:
For Invalid Mail Id’s:
Result:
Thus the above program has been executed successfully.
EX.NO: 05
DATE: LOGIN & REGISTRATION IN MYSQL
Aim:
ALGORITHM:
Step 1: Set up the Flask app and configure the MySQL connection with
the required host, user, password, and database settings. Initialize
MySQL in the app.
Step 2: Create the /login route. On form submission, fetch the username
and password, validate against the database, and initiate a session upon
successful login, or display an error message for incorrect
credentials.
Step 3: Manage user sessions. Use session data to track if a user is
logged in and display the correct interface (e.g., index page for logged-in
users).
Step 4: Implement the /logout route, which clears session data and
redirects the user back to the login page.
Step 5: Set up the /register route. On form submission, validate the
username, password, and email, checking for existing accounts and
correct formatting. Insert the new user into the database if valid.
Step 6: Ensure input validation. Verify that usernames contain only valid
characters, emails match a standard format, and all required fields are
filled out.
Step 7: Use HTML templates for login, registration, and the index page.
Dynamically display messages and content based on the user's
login status using Jinja2.
Step 8: Apply CSS styling for a consistent user interface across login,
registration, and index pages, focusing on buttons, input fields,
and headers.
Step 9: Test to ensure registration, login, logout, and validation function
as expected, and fix any issues with user sessions or input errors.
CODE:
app.py
from flask import Flask, render_template, request, redirect, url_for,
session
from flask_mysqldb import MySQL
import MySQLdb.cursors
import re
app = Flask(__name__)
app.config['MYSQL_HOST'] = 'localhost'
app.config['MYSQL_USER'] = 'root'
app.config['MYSQL_PASSWORD'] = 'gacCS@23'
app.config['MYSQL_DB'] = 'geeklogin'
mysql = MySQL(app)
@app.route('/')
@app.route('/login', methods =['GET', 'POST'])
def login():
msg = ''
if request.method == 'POST' and 'username' in request.form and
'password' in request.form:
username = request.form['username']
password = request.form['password']
cursor =
mysql.connection.cursor(MySQLdb.cursors.DictCursor)
cursor.execute('SELECT * FROM accounts WHERE username
= % s AND password = % s', (username, password, ))
account = cursor.fetchone()
if account:
session['loggedin'] = True
session['id'] = account['id']
session['username'] = account['username']
msg = 'Logged in successfully !'
return render_template('index.html', msg = msg)
else:
msg = 'Incorrect username / password !'
return render_template('login.html', msg = msg)
@app.route('/logout')
def logout():
session.pop('loggedin', None)
session.pop('id', None)
session.pop('username', None)
return redirect(url_for('login'))
login.html:
<html>
<head>
<meta charset="UTF-8">
<title> Login </title>
<link rel="stylesheet" href="{{ url_for('static',
filename='style.css') }}">
</head>
<body></br></br></br></br></br>
<div align="center">
<div align="center" class="border">
<div class="header">
<h1 class="word">Login</h1>
</div></br></br></br>
<h2 class="word">
<form action="{{ url_for('login') }}"
method="post">
<div class="msg">{{ msg }}</div>
<input id="username" name="username"
type="text" placeholder="Enter Your Username"
class="textbox"/></br></br>
<input id="password" name="password"
type="password" placeholder="Enter Your Password"
class="textbox"/></br></br></br>
<input type="submit" class="btn"
value="Sign In"></br></br>
</form>
</h2>
<p class="bottom">Don't have an account? <a
class="bottom" href="{{url_for('register')}}"> Sign Up here</a></p>
</div>
</div>
</body>
</html>
register.html:
<html>
<head>
<meta charset="UTF-8">
<title> Register </title>
<link rel="stylesheet" href="{{ url_for('static',
filename='style.css') }}">
</head>
<body></br></br></br></br></br>
<div align="center">
<div align="center" class="border">
<div class="header">
<h1 class="word">Register</h1>
</div></br></br></br>
<h2 class="word">
<form action="{{ url_for('register') }}"
method="post">
<div class="msg">{{ msg }}</div>
<input id="username" name="username"
type="text" placeholder="Enter Your Username"
class="textbox"/></br></br>
<input id="password" name="password"
type="password" placeholder="Enter Your Password"
class="textbox"/></br></br>
<input id="email" name="email"
type="text" placeholder="Enter Your Email ID"
class="textbox"/></br></br>
<input type="submit" class="btn"
value="Sign Up"></br>
</form>
</h2>
<p class="bottom">Already have an account? <a
class="bottom" href="{{url_for('login')}}"> Sign In here</a></p>
</div>
</div>
</body>
</html>
index.html:
<html>
<head>
<meta charset="UTF-8">
<title> Index </title>
<link rel="stylesheet" href="{{ url_for('static',
filename='style.css') }}">
</head>
<body></br></br></br></br></br>
<div align="center">
<div align="center" class="border">
<div class="header">
<h1 class="word">Index</h1>
</div></br></br></br>
<h1 class="bottom">
Hi {{session.username}}!!</br></br>
Welcome to the index page...
</h1></br></br></br>
<a href="{{ url_for('logout') }}"
class="btn">Logout</a>
</div>
</div>
</body>
</html>
style.css:
.header{
padding: 5px 120px;
width: 150px;
height: 70px;
background-color: #236B8E;
}
.border{
padding: 80px 50px;
width: 400px;
height: 450px;
border: 1px solid #236B8E;
border-radius: 0px;
background-color: #9AC0CD;
}
.btn {
padding: 10px 40px;
background-color: #236B8E;
color: #FFFFFF;
font-style: oblique;
font-weight: bold;
border-radius: 10px;
}
.textbox{
padding: 10px 40px;
background-color: #236B8E;
text-color: #FFFFFF;
border-radius: 10px;
}
::placeholder {
color: #FFFFFF;
opacity: 1;
font-style: oblique;
font-weight: bold;
}
.word{
color: #FFFFFF;
font-style: oblique;
font-weight: bold;
}
.bottom{
color: #236B8E;
font-style: oblique;
font-weight: bold;
}
OUTPUT:
Login Page:
Registration Page:
If Registration Successful:
Result:
Thus the above program has been executed successfully.
EX.NO: 06
DATE: STUDENT MODULE
Aim:
Algorithm:
Step 1: Initialize the Flask application and configure MySQL for
database connectivity, ensuring that event and booking data are stored
and retrieved correctly.
Step 2: Define two main routes: /home for displaying available events
and /book/<event_name> for handling event bookings.
Step 3: In the /home route, connect to the MySQL database, fetch all
events using an SQL query, and pass the event data to the home.html
page for rendering.
Step 4: In the /book/<event_name> route, query the database for the
details of the selected event and display the booking form on book.html.
Step 5: When the user submits the form in /book/<event_name>,
retrieve the user's booking information, including their name, email, and
number of seats and store this information in the booked table of the
database.
Step 6: Use Flask's flash function to display a success message
confirming that the booking has been recorded, then redirect the user
back to the homepage.
Step 7: Render the home.html page with event data displayed in a table,
where users can click "Book Now" to access the booking form for each
event.
Step 8: In the book.html page, display event details and provide input
fields for the user's booking information, pre-filling certain fields with
event data.
Step 9: Upon form submission, validate the data, update the database
with the booking, and display confirmation feedback to the user.
Step 10: Run the Flask application, ensuring the server is responsive to
user actions like viewing events, booking tickets, and receiving booking
confirmations.
CODE:
app.py
from flask import Flask, render_template, request, url_for, redirect, flash,
session
from flask_mysqldb import MySQL
import MySQLdb.cursors
app = Flask(__name__)
app.config['MYSQL_HOST'] = 'localhost'
app.config['MYSQL_USER'] = 'root' app.config['MYSQL_PASSWORD']
= 'root' app.config['MYSQL_DB'] = 'flask'
mysql = MySQL(app)
@app.route('/')
@app.route("/home", methods=["GET"])
def home():
cur = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
cur.execute("SELECT * FROM events")
events = cur.fetchall()
cur.close()
return render_template("home.html", events=events)
if request.method == "POST":
name = request.form["name"]
mail = request.form["mail"]
mobile = request.form["mobile"]
date = request.form["event_date"]
time = request.form["event-time"]
venue = request.form["venue"]
seats = request.form["seats"]
cur = mysql.connection.cursor()
cur.execute("INSERT INTO booked (name, email, mobile,
event_name, event_date, event_time, venue, seats) VALUES (%s, %s, %s,
%s, %s, %s, %s, %s)",
(name, mail, mobile, event_name, date, time, venue, seats))
mysql.connection.commit()
cur.close()
home.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,
initial-scale=1.0">
<title>Events Home</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 20px;
}
h1 {
text-align: center;
}
table {
width: 100%;
border-collapse: collapse;
margin-bottom: 20px;
}
table, th, td {
border: 1px solid #ddd;
}
th, td {
padding: 8px;
text-align: center;
}
th {
background-color: #f2f2f2;
}
button {
padding: 8px 12px;
border: none;
border-radius: 4px;
cursor: pointer;
}
.btn-book {
background-color: #28a745;
color: white;
}
.btn-book:hover {
background-color: #218838;
}
.flash-success {
color: green;
text-align: center;
}
</style>
</head>
<body>
<h1>Available Events</h1>
<table>
<tr>
<th>Event Name</th>
<th>Date</th>
<th>Venue</th>
<th>Action</th>
</tr>
{% for event in events %}
<tr>
<td>{{ event['event_name'] }}</td>
<td>{{ event['date'] }}</td>
<td>{{ event['venue'] }}</td>
<td>
<a href="{{ url_for('book', event_name=event['event_name'])
}}">
<button class="btn-book">Book Now</button>
</a>
</td>
</tr>
{% endfor %}
</table>
OUTPUT:
Home Page
Booking a Event
Booked Success
Result:
Thus the above program has been executed successfully.
EX.NO: 07
DATE: STAFF MODULE
Aim:
Algorithm:
Step 1: Import the necessary libraries, including Flask for web handling
and MySQL for database interactions.
Step 4: Define the "/host" route to handle event creation. In the POST
request, extract event details (event name, date, venue) from the form.
Step 5: Within the "/host" route, connect to the MySQL database and
insert the event into the "events" table.
Step 6: After inserting the event, flash a success message to inform the
user of the successful event creation and redirect to the home page.
Step 7: Define the "/home" route to display all events. In the GET
request, fetch all event records from the "events" table.
Step 8: Render the "home.html" template with the retrieved event data
to display the list of events on the home page.
Step 12: Define the "/booked" route to display booked events. In a GET
request, retrieve all booked event records from the "booked" table and
render the "booked.html" template with the data.
Step 13: Run the Flask application in debug mode to facilitate error
detection during development.
CODE:
app.py
from flask import Flask, render_template, request, url_for, redirect, flash,
session
from flask_mysqldb import MySQL
import MySQLdb.cursors
app = Flask(__name__)
app.config['MYSQL_HOST'] = 'localhost'
app.config['MYSQL_USER'] = 'root' # replace with your MySQL
username
app.config['MYSQL_PASSWORD'] = 'root' # replace with your MySQL
password
app.config['MYSQL_DB'] = 'flask' # replace with your database name
mysql = MySQL(app)
cur = mysql.connection.cursor()
cur.execute("INSERT INTO events (event_name, date, venue)
VALUES (%s, %s, %s)",
(event_name, date, venue))
mysql.connection.commit()
cur.close()
return render_template("host.html")
@app.route('/')
@app.route('/home',methods=["GET","POST"])
def home():
if request.method == "GET":
cur = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
cur.execute("SELECT * FROM events")
events = cur.fetchall()
cur.close()
return render_template("home.html",events=events)
return render_template("home.html")
if request.method == "POST":
new_event_name = request.form["hostevent"]
date = request.form["hostdate"]
venue = request.form["venue"]
cur = mysql.connection.cursor()
cur.execute("UPDATE events SET event_name = %s, date = %s,
venue = %s WHERE event_name = %s",
(new_event_name, date, venue, event_name))
mysql.connection.commit()
cur.close()
@app.route("/delete/<event_name>")
def delete(event_name):
cur = mysql.connection.cursor()
cur.execute("DELETE FROM events WHERE event_name = %s",
(event_name,))
mysql.connection.commit()
cur.close()
@app.route("/booked",methods=["GET"])
def booked():
if request.method == "GET":
cur = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
cur.execute("SELECT * FROM booked")
booked = cur.fetchall()
cur.close()
return render_template("booked.html",booked=booked)
return render_template("booked.html")
if __name__ == "__main__":
app.run(debug=True)
booked.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,
initial-scale=1.0">
<title>Booked Events</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 20px;
}
table {
width: 100%;
border-collapse: collapse;
}
table, th, td {
border: 1px solid #ddd;
}
th, td {
padding: 8px;
text-align: center;
}
th {
background-color: #f2f2f2;
}
button {
padding: 5px 10px;
border: none;
border-radius: 4px;
cursor: pointer;
}
</style>
</head>
<body>
<h1>Booked Events</h1>
<table>
<tr>
<th>Name</th>
<th>Email</th>
<th>Mobile</th>
<th>Event Name</th>
<th>Event Date</th>
<th>Event Time</th>
<th>Venue</th>
<th>Seats</th>
</tr>
{% for book in booked %}
<tr>
<td>{{ book['name'] }}</td>
<td>{{ book['email'] }}</td>
<td>{{ book['mobile'] }}</td>
<td>{{ book['event_name'] }}</td>
<td>{{ book['event_date'] }}</td>
<td>{{ book['event_time'] }}</td>
<td>{{ book['venue'] }}</td>
<td>{{ book['seats'] }}</td>
</tr>
{% endfor %}
</table>
</body>
</html>
home.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,
initial-scale=1.0">
<title>Events</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 20px;
}
table {
width: 100%;
border-collapse: collapse;
}
table, th, td {
border: 1px solid #ddd;
}
th, td {
padding: 8px;
text-align: center;
}
th {
background-color: #f2f2f2;
}
button {
padding: 5px 10px;
border: none;
border-radius: 4px;
cursor: pointer;
}
.btn-host{
margin-top: 25%;
background-color: green;
color: white;
}
.btn-edit {
background-color: #007bff;
color: white;
}
.btn-edit:hover {
background-color: #0056b3;
}
.btn-delete {
background-color: #dc3545;
color: white;
}
.btn-delete:hover {
background-color: #c82333;
}
div{
display: flex;
justify-content: space-evenly ;
}
</style>
</head>
<body>
<div>
<h1>All Events</h1>
<a href="{{url_for('host')}}"><button class="btn-host">Host
Event</button> </a>
<a href="{{url_for('booked')}}"><button class="btn-host">Booked
Event</button> </a>
</div>
<table>
<tr>
<th>Event Name</th>
<th>Date</th>
<th>Venue</th>
<th>Actions</th>
</tr>
{% for event in events %}
<tr>
<td>{{ event['event_name'] }}</td>
<td>{{ event['date'] }}</td>
<td>{{ event['venue'] }}</td>
<td>
<a href="{{ url_for('update', event_name=event['event_name'])
}}">
<button class="btn-edit">Edit</button>
</a>
<a href="{{ url_for('delete', event_name=event['event_name'])
}}">
<button class="btn-delete">Delete</button>
</a>
</td>
</tr>
{% endfor %}
</table>
host.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,
initial-scale=1.0">
<title>Host Event</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 20px;
}
form {
background-color: white;
padding: 20px;
border-radius: 5px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
max-width: 400px;
margin: auto;
}
label, input, button {
display: block;
width: 100%;
margin-bottom: 15px;
}
input[type="text"], input[type="date"] {
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
}
button {
padding: 10px;
border: none;
border-radius: 4px;
background-color: #28a745;
color: white;
cursor: pointer;
}
button:hover {
background-color: #218838;
}
.flash-success {
color: green;
}
.flash-danger {
color: red;
}
</style>
</head>
<body>
<h1>Host a New Event</h1>
<form method="POST" action="{{ url_for('host') }}">
<label for="hostevent">Event Name</label>
<input type="text" id="hostevent" name="hostevent" required>
<label for="hostdate">Date</label>
<input type="date" id="hostdate" name="hostdate" required>
<label for="venue">Venue</label>
<input type="text" id="venue" name="venue" required>
update.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,
initial-scale=1.0">
<title>Update Event</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 20px;
}
form {
background-color: white;
padding: 20px;
border-radius: 5px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
max-width: 400px;
margin: auto;
}
label, input, button {
display: block;
width: 100%;
margin-bottom: 15px;
}
input[type="text"], input[type="date"] {
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
}
button {
padding: 10px;
border: none;
border-radius: 4px;
background-color: #007bff;
color: white;
cursor: pointer;
}
button:hover {
background-color: #0056b3;
}
.flash-success {
color: green;
}
.flash-danger {
color: red;
}
</style>
</head>
<body>
<h1>Update Event</h1>
<form method="POST" action="{{ url_for('update',
event_name=event['event_name']) }}">
<label for="hostevent">Event Name</label>
<input type="text" id="hostevent" name="hostevent" value="{{
event['event_name'] }}" required>
<label for="hostdate">Date</label>
<input type="date" id="hostdate" name="hostdate" value="{{
event['date'] }}" required>
<label for="venue">Venue</label>
<input type="text" id="venue" name="venue" value="{{
event['venue'] }}" required>
OUTPUT:
Home Page
Updated Success
Result:
Thus the above program has been executed successfully.