Backend of our project, made using Django Rest Framework. Used to evaluate a fair division using Fairpy implementations as well as to save/restore user sessions using Firebase database.
Deployed with Render.
-
Clone Repository
git clone https://github.com/FairCoalitionCasesDistributionProject/Backend.git -
Virtual Environment Setup
It is strongly recommended to use python virtual environment. For more information.-
Installation
pip install --user virtualenv -
Creation
python -m venv env -
Activation
.\env\Scripts\activate
-
-
For Linux
-
Install the virtual environment
pip install virtualenv -
Creation
virtualenv env -
Activation
source env/bin/activate
-
-
Dependencies installation
pip install -r requirements.txt
This project uses environment variables for all sensitive configuration. You must create a .env file in the project root before running the server.
You can copy the template:
cp env.example .envThen fill in all required values (see below).
DJANGO_SECRET_KEY- Django secret key (generate withpython generate_secret_key.py)DEBUG- Set toFalsefor productionALLOWED_HOSTS- Comma-separated list of allowed hostsCORS_ALLOWED_ORIGINS- Comma-separated list of allowed CORS originsDATABASE_URL- (Optional) Production database URL- Firebase Configuration:
FIREBASE_API_KEYFIREBASE_AUTH_DOMAINFIREBASE_PROJECT_IDFIREBASE_STORAGE_BUCKETFIREBASE_MESSAGING_SENDER_IDFIREBASE_APP_IDFIREBASE_DATABASE_URL
Never commit your .env file or secrets to version control!
Run the following script to generate a secure Django secret key:
python generate_secret_key.pyCopy the output and paste it into your .env file as DJANGO_SECRET_KEY.
Run at the main directory:
python manage.py runserver
Can be viewed at the url:
http://127.0.0.1:8000/api/
At the form send a json using the format:
{"key": "1.1", "items": 3, "mandates": [1, 1], "preferences": [[1, 1, 1], [1, 1, 1]]}
At the main directory run:
python manage.py test
- All secrets and sensitive configuration are managed via environment variables.
- CORS and allowed hosts are restricted for security.
- Security headers and rate limiting are enforced.
- Input validation and sanitization are implemented.
- See SECURITY.md for full details and deployment checklist.
- Set all environment variables in your production environment.
- Set
DEBUG=Falseand restrictALLOWED_HOSTSandCORS_ALLOWED_ORIGINS. - Use HTTPS in production.
- Review SECURITY.md for more best practices.
For any security issues, see SECURITY.md or contact the development team immediately.