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['name']
        description = request.form['description']
        date = request.form['date']
        location = request.form['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>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
    <title>Event Management System</title>
</head>
<body>
    <h1>Events</h1>
    <a href="{{ url_for('create_event') }}">Create New Event</a>
    <ul>
        {% for event in events %}
            <li>
                <a href="{{ url_for('event_details', event_id=event[0]) }}">{{ event[1] }}</a> - {{ event[3] }} @ {{ event[4] }}
            </li>
        {% endfor %}
    </ul>
</body>
</html>

templates/create_event.html

This allows users to create new events.

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

templates/event_details.html

This shows the details of a single event.

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


Comments

Leave a Reply

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