A modern, real-time polling application built with Django and WebSockets. Users can create polls, vote on them, and see live results update across all connected clients.
- Real-Time Updates: Live poll results powered by Django Channels and WebSockets
- User Authentication: Sign up and login with django-allauth (supports Google OAuth)
- Create & Vote: Create custom polls and vote on existing ones
- Live Results Dashboard: Beautiful, interactive results page with live vote counts and charts
- Responsive Design: Modern UI with Bootstrap styling
- Vote Prevention: Users can only vote once per poll with session tracking
- Backend: Django 5.2.7
- Real-Time: Django Channels 4.0.0, Daphne 4.1.2
- Frontend: HTML5, JavaScript, Bootstrap 5, Chart.js
- Authentication: django-allauth with Google OAuth
- WebSocket Server: Daphne ASGI server
- Channel Layer: In-memory (development) or Redis (production)
- Database: SQLite3
- Python 3.8+
- Redis (optional, for production scaling)
-
Clone the repository
git clone https://github.com/abdu1918sr/Advanced_programming_project.git cd polling_project -
Create a virtual environment
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
-
Apply migrations
python manage.py migrate
-
Create a superuser (optional)
python manage.py createsuperuser
-
Load demo data (optional)
python manage.py seed_demo
Run Daphne ASGI server on Windows:
daphne -b 0.0.0.0 -p 8000 polling_project.asgi:applicationOr on Linux/Mac:
daphne -b 127.0.0.1 -p 8000 polling_project.asgi:applicationThen open your browser to: http://localhost:8000
python manage.py runserverpolling_project/
βββ manage.py # Django management script
βββ requirements.txt # Python dependencies
βββ db.sqlite3 # SQLite database
βββ README.md # This file
βββ polling_project/ # Main project settings
β βββ settings.py # Django configuration
β βββ asgi.py # ASGI configuration for WebSockets
β βββ wsgi.py # WSGI configuration
β βββ urls.py # URL routing
βββ polls/ # Main app
βββ models.py # Question and Choice models
βββ views.py # View functions
βββ consumers.py # WebSocket consumer
βββ routing.py # WebSocket URL routing
βββ forms.py # Django forms
βββ urls.py # App URL patterns
βββ admin.py # Django admin config
βββ templates/
β βββ polls/
β βββ base.html # Base template
β βββ index.html # Poll list
β βββ detail.html # Vote page
β βββ results.html # Live results with WebSocket
β βββ create.html # Create poll
β βββ login.html # Login page
β βββ about.html # About page
β βββ contact.html # Contact page
βββ management/
βββ commands/
βββ seed_demo.py # Demo data seeding
- Go to Google Cloud Console
- Create a new project
- Enable Google+ API
- Create OAuth 2.0 credentials (Web application)
- Set authorized redirect URIs to your domain
- Add to environment variables:
export GOOGLE_CLIENT_ID="your-client-id" export GOOGLE_CLIENT_SECRET="your-client-secret"
For scalable WebSocket support across multiple servers:
pip install channels-redisSet environment variable:
export REDIS_URL="redis://localhost:6379"- Uses Django Channels to manage WebSocket connections
- When a vote is cast, all connected clients receive live updates
- Vote counts and progress bars update instantly
- Session-based tracking prevents users from voting twice
- Displays "You already voted" message
- Users can still view results after voting
- Interactive Chart.js bar chart
- Updates in real-time as votes come in
- Color-coded choices with progress bars
/- Home (poll list)/polls/<id>/- Vote on a poll/polls/<id>/results/- View live results/polls/create/- Create new poll/accounts/login/- Login page/accounts/logout/- Logout/admin/- Django admin panel/ws/polls/<id>/- WebSocket endpoint (real-time updates)
const socket = new WebSocket(`ws://${host}/ws/polls/${question_id}/`);{
"type": "init",
"choices": [
{"id": 1, "choice_text": "Option 1", "votes": 5},
{"id": 2, "choice_text": "Option 2", "votes": 3}
]
}- Ensure Daphne is running, not Django's development server
- Check browser console for connection errors (F12 β Console)
- Verify WebSocket URL format in browser DevTools (Network tab)
- Run migrations:
python manage.py migrate - Reset database:
python manage.py migrate --reset
Abdu1918sr
Contributions are welcome! Feel free to open issues or submit pull requests.
Last Updated: January 2026