pip install -r requirements.txtCreate a .env file in the project root and add your secrets and database config:
DB_NAME=your_db_name
DB_USER=your_db_user
DB_USER_PASSWORD=your_db_password
DB_HOST=localhost
DB_PORT=3306
USER_TOKEN=your_api_token
Make sure Redis is installed. Start it with:
redis-serverpython manage.py migratepython manage.py runserverActivate your virtual environment and run:
source venv/bin/activate
uvicorn mcda_api_project.asgi:application --reloadpytestYou can use test_ws.py to test WebSocket connections. Make sure your .env file contains a valid USER_TOKEN.
python test_ws.pyTo create a token for a user, run the following in the Django shell:
python manage.py shellThen, in the shell:
from django.contrib.auth import get_user_model
from rest_framework.authtoken.models import Token
User = get_user_model()
user = User.objects.get(username="your_username") # Replace with your username
token, created = Token.objects.get_or_create(user=user)
print(token.key)Copy the token and use it in your .env or client code for authenticated WebSocket/API requests.
Note:
- For production, configure your database, secrets, and allowed hosts securely.
- Redis is required for Django Channels group messaging and multi-process support.
- Daphne is required for WebSocket support.