This repository contains the source code for the GyroDodge score system.
- Python 3.6+
- Postman (for making API requests)
Inside the project root, create a new virtualenv. A virtualenv is an isolated installation of Python. This ensures that you can have multiple Python projects without worrying about different projects colliding with each other.
python3 -m venv venv
Activate the virtualenv.
Windows:
.\venv\Scripts\activate.bat
macOS / Linux:
source venv/bin/activate
pip3 install -r requirements.txt
Django manages the tables and columns in the database.
This project is configured to use sqlite by default.
Sqlite will store its database in a file called db.sqlite3
.
Run migrations to create and populate the database:
python manage.py migrate
You are almost there. Create your user account and follow the prompts.
python manage.py createsuperuser
Django comes with a webserver for development purposes. Because our GyroDodge game is not running on the same machine as this score backend we must tell the Django development server to accept connections from our Raspberry Pi.
This webserver should not be used to serve the applications on a real production server!
python manage.py runserver 0.0.0.0:8000
0.0.0.0:8000
means 'listen for connections from other computers on the network on port 8000'. Every computer in your network can now talk to the Django development server. This is a security risk so you should only run the above command on a trusted network like your home network.
Now that the development server is running you should be able to access the admin panel.
After logging in with the credentials you created earlier, you should see a "Scores" link. Click it to view all highscore submissions.
There should be none because you didn't create any yet.
We recommend installing Postman for an easier experience. This guide assumes you are using Postman.
-
Start Postman. Open the import wizard via the menu
File / Import...
option and choose theGyroDodge.postman_collection.json
file included in this repository.In the left sidebar you should now see a GyroDodge folder with at least one item in it.
-
Open the 'Post new highscore' item by clicking it. Notice that it is a HTTP POST request to
http://localhost:8000/api/v1/score/new/
-
Navigate to the Body tab. It should already contain a JSON payload:
{ "points": 10 }
points
should be the score you archieved while playing the GyroDodge game.
-
Now make sure you have the development server running and click 'Send'.
-
You should get a 200 OK response like this:
{ "position": 1 }
position
indicates your current position in the leaderboard.
-
Navigate to the score admin: http://localhost:8000/admin/score/score/.
You should see your highscore has been submitted.
See LICENSE