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