githubEdit

Tutorial: Your First Contribution

This tutorial walks you through making your first code contribution to Gyrinx. You'll add a simple page, write tests for it, and follow the complete development workflow.

What You'll Learn

  • How to set up your development environment

  • How to create a view and template following Gyrinx patterns

  • How to write tests for your code

  • How to format code and run the test suite

  • How to create a pull request

Prerequisites

  • Python 3.12+ installed

  • Docker with Compose installed

  • Git installed

  • Basic familiarity with Django

Time Required

Approximately 45-60 minutes


Step 1: Set Up Your Development Environment

If you haven't already, clone the repository and set up your environment:

Checkpoint: Run manage runserver and visit http://localhost:8000 to verify the app works.


Step 2: Create a New Branch

Always work on a feature branch:


Step 3: Create Your View

Let's add a simple "About Development" page to the pages app.

Create the view in gyrinx/pages/views.py. First, check what's already there:

Add a new view function:

Key points:

  • Views are simple functions that take a request and return a response

  • We use render() to render a template

  • Template paths are relative to the templates directory


Step 4: Create the URL Route

Add the URL pattern in gyrinx/pages/urls.py:

Key points:

  • URL patterns use path() with a route, view function, and name

  • The name is used for reverse URL lookups in templates


Step 5: Create the Template

Create the template at gyrinx/pages/templates/pages/about_development.html:

Key points:

  • Extend core/layouts/page.html for simple content pages

  • Use col-12 col-xl-6 for mobile-first responsive layout

  • Keep content in a single column that expands on larger screens


Step 6: Write Tests

Create a test file at gyrinx/pages/tests/test_views.py (create the tests directory if needed):

Key points:

  • Use @pytest.mark.django_db for any test that touches the database

  • Use Django's Client for view testing

  • Test both that the page loads (status code) and contains expected content


Step 7: Run Tests

Run your tests to make sure they pass:

Checkpoint: All tests should pass.


Step 8: Format Your Code

Before committing, format your code:

This runs:

  • ruff for Python linting and formatting

  • djlint for template formatting

  • Other code quality checks


Step 9: Verify Locally

Start the development server and check your work:

Visit http://localhost:8000/about-development/ to see your new page.

Checkpoint: The page should display with proper styling and content.


Step 10: Commit Your Changes

Stage and commit your changes:

The pre-commit hooks will run automatically to check formatting.


Step 11: Push and Create a Pull Request

Push your branch and create a PR:

Then create a pull request on GitHub with:

  • A clear title describing the change

  • A description explaining what and why

  • Reference any related issues


What You Built

You've successfully:

  1. Set up a Gyrinx development environment

  2. Created a Django view following project patterns

  3. Added a URL route

  4. Built a mobile-first template using Bootstrap

  5. Written pytest tests

  6. Formatted code and run the test suite

  7. Created a commit following project conventions

Next Steps

Cleaning Up

If you were just following along and don't want to submit this example:

Last updated