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]
如果您使用的是django 2.0+:
否则:
^{pr2}$你应该把这个放在所有其他url之后,否则它们将停止工作,因为这个模式匹配每个url。在
然后在视图中找到路径:
对于类似
site.com/home/path1/path2/path3/file/
的路径,如果打印folders
,则会得到:相关问题 更多 >
编程相关推荐