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
requestand return a responseWe use
render()to render a templateTemplate 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 nameThe 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.htmlfor simple content pagesUse
col-12 col-xl-6for mobile-first responsive layoutKeep 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_dbfor any test that touches the databaseUse Django's
Clientfor view testingTest 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:
rufffor Python linting and formattingdjlintfor template formattingOther 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:
Set up a Gyrinx development environment
Created a Django view following project patterns
Added a URL route
Built a mobile-first template using Bootstrap
Written pytest tests
Formatted code and run the test suite
Created a commit following project conventions
Next Steps
Read Key Concepts to understand the project architecture
Explore Models and Database to learn about the data layer
Check Frontend Development for styling guidelines
Review Testing for comprehensive testing patterns
Join the Discord to discuss ideas with the team
Cleaning Up
If you were just following along and don't want to submit this example:
Last updated