abhirajadhikary06 / abhirajadhikary06/eventstack
There are many Problems when starting the server. Explaination in description.
- Vorherrschende Sprache
- Python
- Sterne
- 20
- Forks
- 59
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
# 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
Beitragsleitfaden
Bewertung
Dieses Issue wurde noch nicht bewertet.