09-21, 11:15–11:45 (Europe/Lisbon), Auditorium
File-system based routing has been widely used in JavaScript web frameworks
such as Next.js, NuxtJS, Remix, Gatsby, and SvelteKit.
With file-system based routing, the URL structure of your web application
is defined by the structure of the codebase. This makes it easier to find the
view that handles a certain path, and vice versa.
This talk will explore an experiment that implements file-based routing in a Django project.
File-system based routing has been widely used in JavaScript web frameworks
such as Next.js, NuxtJS, Remix, Gatsby, and SvelteKit.
It works by scanning the files in a specific directory (e.g. pages
) and mapping the
default export of each file to a URL route in the web application. This means that each
URL path corresponds to a single view file under the same path in your codebase.
Meanwhile, in Django, URL routes are traditionally defined in a urls.py
file in the
project directory. You can separate the urls.py
into multiple different files and use
include()
to bring them all together. However, you still have to explicitly define each
path and the view it corresponds to.
In this talk, we'll explore how we can implement file-based routing in a Django project to
automatically generate URL paths based on your file structure, as well as the challenges
that come with it.
The talk will be structured as follows:
- What file-system based routing is and why it can be useful
- How it works in other web frameworks
- How it may work in Django
- How it can be implemented
- What challenges we'll face and how to overcome them
- What possible improvements and new ideas we can bring
- How you can use it in your project
Resources:
- Slides
- Repository
Video: https://youtu.be/_2VZ9AOXblY
I'm Sage and I'm from Jakarta, Indonesia.
In 2019, I participated in Google Summer of Code with Django, during which I implemented the cross-database JSONField
that became available in Django 3.1.
Now, I work as a Developer at Torchbox, building new features and improvements to Wagtail CMS and its ecosystem.
Outside of the Django world, I maintain my project giscus, a comment system powered by GitHub Discussions.
I write weekly logs on my personal website and learn guitar in my free time. You can find me @laymonage on GitHub, Twitter, and other sites. I'd love to make friends from around the world, so hit me up!