I’m trying to write a Django URL pattern that matches 1 to n strings separated by slashes. It should match any of these and pass each term to the view:
foo.com/apples
foo.com/apples/oranges
foo.com/oranges/apples/lizards/google_android/adama
In Django I could just pass the entire thing to a view as a string and parse it manually, but I was curious if there is some kind of regex to do this more elegantly.
A regex will always match one substring, not multiple string parts, so it’s not possible for you to get a list instead of a single match.
You should parse the words manually:
Depending on your use case, each word might have a fixed meaning, such as a date or product category. Then you can probably make some of them optional like so: