Quizzes app
An example Django app that serves quizzes and lets people know how they scored. Quizzes and their questions are stored in a PostGreSQL database. There is no user authentication or per-user data stored.
Local development
Install the requirements and Git hooks:
This project has devcontainer support, so you can open it in Github Codespaces or local VS Code with the Dev Containers extension. If you're unable to open the devcontainer, then it's best to first create a Python virtual environment and activate that.
Install the requirements:
python3 -m pip install -r requirements-dev.txt
Create an
.env
file using.env.sample
as a guide. Set the value ofDBNAME
to the name of an existing database in your local PostgreSQL instance. Set the values ofDBHOST
,DBUSER
, andDBPASS
as appropriate for your local PostgreSQL instance. If you're in the devcontainer, copy the values exactly from.env.sample
.Fill in a secret value for
SECRET_KEY
. You can use this command to generate an appropriate value.python -c 'import secrets; print(secrets.token_hex())'
Run the migrations:
python3 manage.py migrate
Run the local server:
python3 manage.py runserver
Navigate to "/quizzes" (since no "/" route is defined) to verify server is working.
Admin
This app comes with the built-in Django admin.
- Create a superuser:
python3 manage.py createsuperuser
Restart the server and navigate to "/admin"
Login with the superuser credentials.
Testing
Run tests:
python3 manage.py collectstatic
coverage run --source='.' manage.py test quizzes
coverage report
The same tests are also run as a Github action.
Deployment
This repository is set up for deployment on Azure App Service (w/PostGreSQL flexible server) using the configuration files in the infra
folder.
- Sign up for a free Azure account
- Install the Azure Dev CLI. (If you open this repository in Codespaces or with the VS Code Dev Containers extension, that part will be done for you.)
- Provision and deploy all the resources:
azd up
- To be able to access
/admin
, you'll need a Django superuser. Navigate to the Azure Portal for the App Service, select SSH, and run this command:
python manage.py createsuperuser
CI/CD pipeline
This project includes a Github workflow for deploying the resources to Azure on every push to main. That workflow requires several Azure-related authentication secrets to be stored as Github action secrets. To set that up, run:
azd pipeline config
Costs
Pricing varies per region and usage, so it isn't possible to predict exact costs for your usage.
You can try the Azure pricing calculator for the resources:
- Azure App Service: Basic Tier with 1 CPU core, 1.75GB RAM. Pricing is hourly. Pricing
- PostgreSQL Flexible Server: Burstable Tier with 1 CPU core, 32GB storage. Pricing is hourly. Pricing
- Virtual Network: Pricing based on data transfer. Pricing
- Private DNS Zone: Pricing based on number of zones per region per month. Pricing
- Log analytics: Pay-as-you-go tier. Costs based on data ingested. Pricing
⚠️ To avoid unnecessary costs, remember to take down your app if it's no longer in use,
either by deleting the resource group in the Portal or running azd down
.
Getting help
If you're working with this project and running into issues, please post in Discussions.