If you are using django 2.0+:
re_path(r'^.*', some_view)
Otherwise:
url(r'^.*', some_view)
You should put this after all other urls otherwise they'll stop working because this pattern matches every url.
And then you get the path in your view:
def some_view(request):
full_path = request.path
split_path = full_path.split('/')
# If you have slash at the end of the url, you should pick the second last item.
if len(split_path[-1] < 1:
file = split_path[-2]
folders = split_path[2:len(split_path)-2]
else:
file = split_path[-1]
folders = split_path[2:len(split_path)-1]
For a path like site.com/home/path1/path2/path3/file/ you'll get this if you print folders:
['path1', 'path2', 'path3']