abhirajadhikary06 / abhirajadhikary06/eventstack
There are many Problems when starting the server. Explaination in description.
- Langage dominant
- Python
- Étoiles
- 20
- Forks
- 59
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
# EventStack Troubleshooting Guide
This document outlines all the issues encountered during the EventStack application setup and their solutions.
## 🚨 Issues Encountered and Solutions
### 1. Module Import Errors
#### Problem
```
ModuleNotFoundError: No module named 'auth'
```
#### Root Cause
The imports in `main.py` were trying to import from module names like `auth`, `events`, etc., but these modules were actually located in the `handlers` directory.
#### Solution
1. **Fixed import paths in `main.py`:**
```python
# Before:
from auth import LoginHandler, GitHubAuthHandler, LogoutHandler
from events import DashboardHandler, EventCreateHandler, ...
# After:
from handlers.auth import LoginHandler, GitHubAuthHandler, LogoutHandler
from handlers.events import DashboardHandler, EventCreateHandler, ...
```
2. **Created missing `__init__.py` file** in the `handlers` directory:
```bash
touch handlers/__init__.py
```
---
### 2. Missing Database Function Error
#### Problem
```
ImportError: cannot import name 'get_upcoming_events' from 'models.db'
```
#### Root Cause
The `DashboardHandler` was trying to import `get_upcoming_events` function that didn't exist in the database module.
#### Solution
**Created the `get_upcoming_events` function** in `models/db.py`:
```python
def get_upcoming_events(limit=None):
"""Get upcoming events (non-finalized events or events with future time slots)"""
conn = get_db_connection()
cursor = conn.cursor()
query = """
SELECT DISTINCT e.*, u.username as creator_username, u.avatar_url as creator_avatar
FROM events e
JOIN users u ON e.created_by = u.id
LEFT JOIN time_slots ts ON e.id = ts.event_id
WHERE (e.is_finalized = 0 OR e.is_finalized IS NULL)
OR (e.is_finalized = 1 AND ts.slot_datetime > datetime('now'))
ORDER BY e.created_at DESC
"""
if limit:
query += f" LIMIT {limit}"
cursor.execute(query)
events = cursor.fetchall()
cursor.close()
conn.close()
return [dict(event) for event in events]
```
---
### 3. Handler Import Location Error
#### Problem
```
ImportError: cannot import name 'ContactHandler' from 'handlers.events'
```
#### Root Cause
`ContactHandler` was being imported from `handlers.events` but it actually exists in `handlers.info`.
#### Solution
**Fixed import statement in `main.py`:**
```python
# Before:
from handlers.events import (
DashboardHandler, EventCreateHandler, EventViewHandler,
EventVoteHandler, EventEditHandler, ContactHandler # Wrong location
)
# After:
from handlers.events import (
DashboardHandler, EventCreateHandler, EventViewHandler,
EventVoteHandler, EventEditHandler
)
from handlers.info import AboutHandler, PrivacyHandler, SupportHandler, ContactHandler
```
---
### 4. Docker Port Configuration Mismatch
#### Problem
Server startup issues due to port misconfiguration in Docker setup.
#### Root Cause
Port mismatch between different configuration files:
- `main.py` defaulted to port 8888
- `Dockerfile` exposed port 5050
- `docker-compose.yml` mapped port 5050:5050
#### Solution
**Updated `docker-compose.yml`** to set the PORT environment variable:
```yaml
environment:
- COOKIE_SECRET=your-secret-key-change-in-production
- PORT=5050 # Added this line
```
---
### 5. Tornado Template Syntax Errors
#### Problem
```
tornado.template.ParseError: unknown operator: 'endblock' at base.html:6
tornado.template.ParseError: unknown operator: 'with' at base.html:106
```
#### Root Cause
Templates were using Django/Jinja2 syntax instead of Tornado template syntax.
#### Solutions
**5.1 Fixed template block endings:**
```html
{% block title %}EventStack{% endblock %}
{% if user %}...{% endif %}
{% for item in items %}...{% endfor %}
{% with messages = get_messages() %}...{% endwith %}
{% block title %}EventStack{% end %}
{% if user %}...{% end %}
{% for item in items %}...{% end %}
```
**5.2 Fixed static file references:**
```html
{{ url_for('static', path='css/custom.css') }}
{{ static_url('css/custom.css') }}
```
**5.3 Fixed URL references:**
```html
Login
```
---
### 6. URL Routing Error
#### Problem
```
404 GET /auth/github (172.18.0.1) 1.46ms
```
#### Root Cause
The login template was linking to `/auth/github` but the route was only configured as `/complete/github`.
#### Solution
**Added missing route in `main.py`:**
```python
return tornado.web.Application([
(r"/", LoginHandler),
(r"/login", LoginHandler),
(r"/logout", LogoutHandler),
(r"/auth/github", GitHubAuthHandler), # Added this line
(r"/complete/github", GitHubAuthHandler), # Existing callback route
# ... other routes
])
```
---
## 🔧 Additional Enhancements
### Flash Messages System Implementation
Since Tornado doesn't support Django-style flash messages with `{% with %}`, we implemented a custom flash message system:
**Created `utils/flash.py`:**
```python
class FlashMessages:
@staticmethod
def success(handler, message):
# Implementation for success messages
@staticmethod
def error(handler, message):
# Implementation for error messages
@staticmethod
def get_messages(handler):
# Retrieve and clear messages
```
**Updated templates to display flash messages:**
```html
{% if flash_messages %}
{% for category, message in flash_messages %}
{{ message }}
{% end %}
{% end %}
```
---
## 📁 File Structure After Fixes
```
eventstack/
├── handlers/
│ ├── __init__.py # ✅ Created
│ ├── auth.py # 🔧 Modified (BaseHandler, flash messages)
│ ├── events.py # 🔧 Modified (imports, BaseAuthHandler)
│ ├── info.py # 📁 Existing
│ └── websocket.py # 📁 Existing
├── models/
│ ├── db.py # 🔧 Modified (added get_upcoming_events)
│ └── schema.sql # 📁 Existing
├── templates/
│ ├── base.html # 🔧 Fixed template syntax, added flash messages
│ ├── index.html # 🔧 Fixed template syntax
│ ├── login.html # 📁 Existing
│ └── ... # Other templates
├── utils/
│ ├── __init__.py # ✅ Created
│ └── flash.py # ✅ Created
├── static/
│ ├── css/
│ ├── images/
│ └── js/
├── main.py # 🔧 Fixed imports, routing, added DB init
├── docker-compose.yml # 🔧 Fixed port configuration
├── Dockerfile # 📁 Existing
├── requirements.txt # 📁 Existing
└── TROUBLESHOOTING.md # ✅ This file
```
---
## 🚀 Final Status
✅ **All import errors resolved**
✅ **All template syntax errors fixed**
✅ **Docker configuration corrected**
✅ **URL routing issues resolved**
✅ **Flash message system implemented**
✅ **Database initialization added**
✅ **Server successfully running on `http://localhost:5050`**
---
## 🔄 How to Run the Application
1. **Clone the repository**
2. **Navigate to the eventstack directory**
3. **Build and run with Docker:**
```bash
docker compose build
docker compose up
```
4. **Access the application at:** `http://localhost:5050`
---
## 🛠️ Development Notes
- **Framework:** Tornado (Python web framework)
- **Database:** SQLite with custom ORM functions
- **Templates:** Tornado template engine (not Jinja2/Django)
- **Authentication:** GitHub OAuth
- **Styling:** Tailwind CSS
- **Container:** Docker with docker-compose
---
## 📝 Lessons Learned
1. **Always check import paths** when modules are organized in subdirectories
2. **Tornado template syntax** is different from Django/Jinja2
3. **Docker port configuration** must be consistent across all files
4. **Missing `__init__.py`** files can cause import errors
5. **Template engine compatibility** is crucial when migrating between frameworks
Guide de contribution
Ouvrir le guide de contribution
Évaluation
Cette issue n'a pas encore été évaluée.