Home > Net >  Get slug name list by url path name
Get slug name list by url path name

Time:10-06

I am reverse-engineering django urlpatterns. For my purpose, I need to dynamically know the list of slug names developers chose to use within url. (for weird decorator purposes outside of scope of this question)

Example:

path("<slug:membership_slug>/<slug:parent_slug>/data/", rzd.ReportingUnitDataView.as_view(), name="hierarchy.item.data"),

So, in the world, where everyone writes perfect code, my function whould take "hierarcy.item.data" and spit out ["membership_slug", "parent_slug"]

I looked at the reverse function, hoping it would return something useful without kwargs, but it does not. Have been googling like Neo, but the hope does not leave my heart... somewhere django should hold all that urlpatterns stuff! I still believe.

Perhaps you can at suggest how to get a hold of list of urls, even if in the raw format, that would already be a help. Thank you.

CodePudding user response:

Search for book called Django 2x scopes this book hold every thing related to django best practices and of course the urls part.

This book will help you to understand more how django developers think.

Happy hacking

  • Related