I have a website in which I want my api nodes not end with trailing slashes. In my main urls.py
I have
# urls.py
path("api/", include("api.urls")),
And inside my api
app I have my regular api nodes:
# api/urls.py
path("", TemplateView.as_view(template_name="index.html")),
path("runs", views.RunListView.as_view(), name="run-list"),
...
That will give me urls like /api/
, /api/runs
, etc. So far so good. But if I want my “root” app node also have no trailing slash, I would do:
# urls.py
path("api", include("api.urls")),
# api/urls.py
path("", TemplateView.as_view(template_name="index.html")),
path("/runs", views.RunListView.as_view(), name="run-list"),
...
I now need to prepend a slash to all of my nodes inside the app! Is that right? Is that considered a good practice? Somehow it does not sound like a good practice to me. I’m more used to have paths of the type “my-path/” or “my-path” but never “/my-path”.
Please tell me if you have any experience on this and whether you think this pattern is common.