From 9e2674b5ebf48948aaa88bc3a994ad321887c4e7 Mon Sep 17 00:00:00 2001 From: Radoslav Georgiev Date: Wed, 6 Apr 2022 14:46:15 +0300 Subject: [PATCH] Add a "tree-like" example for urls --- README.md | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/README.md b/README.md index 7b6e2e2..559d08a 100644 --- a/README.md +++ b/README.md @@ -1281,6 +1281,58 @@ urlpatterns = [ **Splitting urls like that can give you the extra flexibility to move separate domain patterns to separate modules**, especially for really big projects, where you'll often have merge conflicts in `urls.py`. +Now, if you like to see the entire url tree structure, you can do just that, by not extracting specific variables for the urls that you include. + +Here's an example from our [Django Styleguide Example](https://github.com/HackSoftware/Django-Styleguide-Example/blob/master/styleguide_example/files/urls.py): + +```python +from django.urls import path, include + +from styleguide_example.files.apis import ( + FileDirectUploadApi, + + FilePassThruUploadStartApi, + FilePassThruUploadFinishApi, + FilePassThruUploadLocalApi, +) + + +urlpatterns = [ + path( + "upload/", + include(([ + path( + "direct/", + FileDirectUploadApi.as_view(), + name="direct" + ), + path( + "pass-thru/", + include(([ + path( + "start/", + FilePassThruUploadStartApi.as_view(), + name="start" + ), + path( + "finish/", + FilePassThruUploadFinishApi.as_view(), + name="finish" + ), + path( + "local//", + FilePassThruUploadLocalApi.as_view(), + name="local" + ) + ], "pass-thru")) + ) + ], "upload")) + ) +] +``` + +Some people prefer the first way of doing it, others prefer the visible tree-like structure. This is up to you & your team. + ## Settings When it comes to Django settings, we tend to follow the folder structure from [`cookiecutter-django`](https://github.com/cookiecutter/cookiecutter-django), with few adjustments: