Data API for the (upcoming) F-Zero Central website. Uses the Django web framework.
- Ensure you have the following installed:
- Python 3.10.x
- PostgreSQL 10 or higher (see below section for a sample PostgreSQL setup)
- On Ubuntu, the following apt packages:
python3.10-dev,python3.10-venv,libpq-dev
git clonethis repository.- Set up a virtual environment and install Python packages there:
- Create a virtual environment at the directory of your choice (can be outside of the repository):
python3.10 -m venv <path/to/environment> - Activate your environment:
source <path/to/environment>/bin/activateon Linux,<path/to/environment>/Scripts/activateon Windows. - If on Linux, run
pip install wheel - Run
pip install -r requirements/development.txtto install packages to your environment. Ensure that there are no installation errors.
- Create a virtual environment at the directory of your choice (can be outside of the repository):
- Create an
.envfile at the root of this repository. Specify configuration variable values in this file, using the.env.distfile as a template. - Set an environment variable to specify you're using the 'development' settings module.
export DJANGO_SETTINGS_MODULE=config.settings.developmenton Linux,set DJANGO_SETTINGS_MODULE=config.settings.developmenton Windows. - Run
python manage.py migrateto create the database schema.
sudo apt install postgresqlsudo -u postgres psqlto enter the psql shell with the newly-created Linux userpostgres, which is tied to the default PostgreSQL userpostgres.- On the psql shell:
CREATE USER django WITH PASSWORD 'mypassword';replacing mypassword with the DATABASE_PASSWORD set in your.envfile.ALTER ROLE django SET client_encoding TO 'utf8';- this and the following two commands are for optimizing Django's connections to PostgreSQL.ALTER ROLE django SET default_transaction_isolation TO 'read committed';ALTER ROLE django SET timezone TO 'UTC';CREATE DATABASE mydatabase;replacing mydatabase with your DATABASE_NAME.GRANT ALL PRIVILEGES ON DATABASE mydatabase TO django;\qto exit the psql shell.
- If you've got your Python environment all set up, you can run
python manage.py dbshellto test entering the psql shell through Django's settings. Then run\con the psql shell to confirm the user and database names.
- Set the environment variable to specify your settings module (see above).
- Activate your virtual environment (see above).
- From the
projectdirectory, run:python manage.py runserver- You can specify a port number after
runserverto serve the API at that port.
- You can specify a port number after
- The website should be served at your localhost address. For example, if it's
127.0.0.1:8000, try visitinghttp://127.0.0.1:8000/gamesin your browser.
- Set the environment variable to specify your settings module (see above).
- Activate your virtual environment (see above).
- From the
projectdirectory, run:python manage.py test
- When using the PyCharm IDE, if many import statements such as
from games.models import Gameare getting red-underlined, try right-clicking theprojectdirectory, and choose Mark Directory as -> Sources Root. - Firefox may not know how to display responses of the content type
application/vnd.api+json. One add-on that can help with this is JSON Lite.