The Django Quiz app has been developed to provide the user with a trivia question. The game can be played either completely randomly, or by choosing options to filter the difficulty, category and question type.
** The link to the live page can be found here. **
- Play the game with randomized questions.
- Be able to choose a category setting.
- Be able to choose a difficulty setting.
- Be able to choose a question type setting.
- Be able to combine the above.
- See my answer result.
The homepage provides instructions on how to use the app.
- You can ignore the form and press the green "Start" button to get a randomized question from the database.
- You can use the form to choose a Difficulty, Category and/or Question Type option.
- If you do, when they press "Start" they will get a random question based on those parameters.
- You can always press the "Django Quiz" link on top to get to the home page.
- Django -> Framework to build the app
- Open Trivia API -> API to get questions and relevant categories
- ElephantSQL -> Free PostgreSQL database used to store data
- Coverage -> Used to document testing
- The app has no Static files, so no static hosting service was used
The app has been deployed to Heroku, so users can follow this link to access it.
- You can fork the repository by clicking the "Fork" button on the top right of the repository page, here.
- After you have a repository, open it in your IDE of choice.
- Install dependencies with the command
pip3 install > requirements.txt
- Open a terminal in the main folder of the repository (or use your IDE's terminal) and run the command
python3 populate_questions.py
The populate_questions.py file will make a request to the Open Trivia API to get all categories and then populate 50 questions per category. You can edit line 30 to change the amount of questions. In the url, change amount to the amount you want.
https://opentdb.com/api.php?amount=AMOUNT_YOU_WANT&category={category["id"]}&token={token}
The categories.json and questions.json files already contain data which you can use. Running the command to update them will erase old data and populate it with new.
- You will need to create an env.py file and set the following environment variables in it:
SECRET_KEY = YOUR_DJANGO_SECRET_KEY
DATABASE_URL = YOUR_DATABASE_URL
PostgreSQL on the page ElephantSQL was used when creating the app, yet you can use any RDBMS of choice.
- Run the migration commands to migrate the models:
python3 manage.py makemigrations
andpython3 manage.py migrate
- You will need to load the new categories and questions in the database with the following commands:
python3 manage.py loaddata categories.json
andpython3 manage.py loaddata questions.json
- You will need to set new values for ALLOWED_HOSTS and CSRF_TRUSTED_ORIGINS in your settings.py file to match your own URLs.
- The app should now be ready. You can run the server in your IDE with
python3 manage.py runserver
- Go to Heroku and sign up/sign in.
- Create a new app with the desired name.
- Go to the app's Settings tab and set up your environment variables (the ones mentioned above) in the Config Vars.
- On the app's Deploy page, you can connect it to your GitHub repository (the one for the app) and set up manual or automatic deployment.
The app already has a Procfile for Heroku and the requirements.txt file, so Heroku knows which dependencies to install and how to use the app.
- After a successful deployment, you can open the app with the "Open app" button on the top-right.
Unit testing was conducted with the Django test suite and was documented with the coverage library. Models, views and forms are reported as 100% tested in coverage.
- Play the game with randomized questions.
Action | Expected Result | Actual Result |
---|---|---|
Press "Start" without any form options chosen | Get random question | Works as expected |
- Be able to choose a category setting.
Action | Expected Result | Actual Result |
---|---|---|
Press "Start" after choosing a category | Get question from category | Works as expected |
- Be able to choose a difficulty setting.
Action | Expected Result | Actual Result |
---|---|---|
Press "Start" after choosing a difficulty | Get question from difficulty | Works as expected |
- Be able to choose a question type setting.
Action | Expected Result | Actual Result |
---|---|---|
Press "Start" after choosing a question type | Get question from question type | Works as expected |
- Be able to combine the above.
Action | Expected Result | Actual Result |
---|---|---|
Press "Start" after choosing a combination of settings | Get question from combination | Works as expected |