My Blog

My WordPress Blog

My Blog

My WordPress Blog

Event Management System

You can install Flask using pip if you haven’t already:

pip install Flask

Project Structure

event_management_system/
├── app.py
├── templates/
│   ├── index.html
│   ├── create_event.html
│   └── event_details.html
└── static/
    └── style.css

Step 1: Setting Up Flask

app.py

This will be the main application file.

from flask import Flask, render_template, request, redirect, url_for
import sqlite3

app = Flask(__name__)

# Database setup
def init_db():
with sqlite3.connect("events.db") as conn:
    cursor = conn.cursor()
    cursor.execute('''
        CREATE TABLE IF NOT EXISTS events (
            id INTEGER PRIMARY KEY,
            name TEXT NOT NULL,
            description TEXT NOT NULL,
            date TEXT NOT NULL,
            location TEXT NOT NULL
        )
    ''')
    conn.commit()
@app.route('/') def index():
conn = sqlite3.connect("events.db")
cursor = conn.cursor()
cursor.execute("SELECT * FROM events")
events = cursor.fetchall()
conn.close()
return render_template('index.html', events=events)
@app.route('/event/<int:event_id>') def event_details(event_id):
conn = sqlite3.connect("events.db")
cursor = conn.cursor()
cursor.execute("SELECT * FROM events WHERE id = ?", (event_id,))
event = cursor.fetchone()
conn.close()
return render_template('event_details.html', event=event)
@app.route('/create_event', methods=['GET', 'POST']) def create_event():
if request.method == 'POST':
    name = request.form&#91;'name']
    description = request.form&#91;'description']
    date = request.form&#91;'date']
    location = request.form&#91;'location']
    
    conn = sqlite3.connect("events.db")
    cursor = conn.cursor()
    cursor.execute("INSERT INTO events (name, description, date, location) VALUES (?, ?, ?, ?)",
                   (name, description, date, location))
    conn.commit()
    conn.close()
    
    return redirect(url_for('index'))

return render_template('create_event.html')
if __name__ == '__main__':
init_db()
app.run(debug=True)

Step 2: Creating HTML Templates

templates/index.html

This will display all events.

<!DOCTYPE html>
<html lang="en">
<head>
&lt;meta charset="UTF-8">
&lt;meta name="viewport" content="width=device-width, initial-scale=1.0">
&lt;link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
&lt;title>Event Management System&lt;/title>
</head> <body>
&lt;h1>Events&lt;/h1>
&lt;a href="{{ url_for('create_event') }}">Create New Event&lt;/a>
&lt;ul>
    {% for event in events %}
        &lt;li>
            &lt;a href="{{ url_for('event_details', event_id=event&#91;0]) }}">{{ event&#91;1] }}&lt;/a> - {{ event&#91;3] }} @ {{ event&#91;4] }}
        &lt;/li>
    {% endfor %}
&lt;/ul>
</body> </html>

templates/create_event.html

This allows users to create new events.

<!DOCTYPE html>
<html lang="en">
<head>
&lt;meta charset="UTF-8">
&lt;meta name="viewport" content="width=device-width, initial-scale=1.0">
&lt;link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
&lt;title>Create Event&lt;/title>
</head> <body>
&lt;h1>Create New Event&lt;/h1>
&lt;form method="POST">
    &lt;label>Name: &lt;input type="text" name="name" required>&lt;/label>&lt;br>
    &lt;label>Description: &lt;textarea name="description" required>&lt;/textarea>&lt;/label>&lt;br>
    &lt;label>Date: &lt;input type="date" name="date" required>&lt;/label>&lt;br>
    &lt;label>Location: &lt;input type="text" name="location" required>&lt;/label>&lt;br>
    &lt;button type="submit">Create Event&lt;/button>
&lt;/form>
&lt;a href="{{ url_for('index') }}">Back to Events&lt;/a>
</body> </html>

templates/event_details.html

This shows the details of a single event.

<!DOCTYPE html>
<html lang="en">
<head>
&lt;meta charset="UTF-8">
&lt;meta name="viewport" content="width=device-width, initial-scale=1.0">
&lt;link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
&lt;title>{{ event&#91;1] }}&lt;/title>
</head> <body>
&lt;h1>{{ event&#91;1] }}&lt;/h1>
&lt;p>{{ event&#91;2] }}&lt;/p>
&lt;p>Date: {{ event&#91;3] }}&lt;/p>
&lt;p>Location: {{ event&#91;4] }}&lt;/p>
&lt;a href="{{ url_for('index') }}">Back to Events&lt;/a>
</body> </html>

Step 3: Add Some Styles

static/style.css

Add some basic styling.

body {
font-family: Arial, sans-serif;
} h1 {
color: #333;
} ul {
list-style-type: none;
} li {
margin: 10px 0;
}

Step 4: Run the Application

Now you can run your application:

bashCopy codepython app.py

Visit http://127.0.0.1:5000 in your web browser, and you should see the Event Management System in action!

Additional Features

This is a basic example. You might want to extend this system with features like:

  • User authentication
  • Event registration
  • Notification system
  • Advanced search functionality

Event Management System

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top