Django for Behavioural Science

Plan for 3 to 4 hours for the core chapters.
This tutorial is the hands-on companion to the paper First Steps in Django Web Development: Applied Examples from Behavioural Research (Woods, currently under peer review). The paper explores why a behavioural scientist might want to build their own web application, with examples drawn from real studies. Here, though, is where you actually build one.
You've built an experiment in jsPsych. It runs great in the browser, but how do you store your results? When your participant closes the tab, their results vanish! This is the job of the backend, and this guide shows you how to build such a backend with Django. Think Pavlovia or Gorilla, but utterly bespoke, so you can add just about any feature you can imagine to make your study more powerful. In one of my own studies that meant wiring in a Raspberry Pi and a webcam, to estimate how many people were milling about a room at key moments.
Other Django tutorials
These are great. You should check them out too!
What you'll build
Here we will be building a small study-hosting platform. A researcher adds a study by pasting in their jsPsych timeline. The platform adds data-capture, serves the study to participants (recruited from Prolific if you want that), and stores study data in a database that you can then browse and export.
A few things to point out
- You can hide the comments in code blocks by clicking above the code block or in the menu bar
- Code blocks have a copy button, top-right corner
- Most blocks have a "… on GitHub" link underneath which takes you to the file on GitHub
- Some terms here have a dotted underline. Hover over, or tap, the term, for a brief explanation (e.g. slug)
- If you spot a mistake, please let me know! Click the GitHub link in the menu bar, then click 'Issues' in GitHub's own menu. Thanks!