有没有办法在匹配url之前更改request.path?

man*_*uel 7 django django-middleware

当我收到包含单词"self"的路径的请求时,我希望在将其与URL匹配之前将其替换为用户ID.我尝试使用这样的中间件:

def process_request(self, request):
    if '/self/' in request.path:
        request.path = request.path.replace('/self/','/' + str(request.user.id) + '/')
Run Code Online (Sandbox Code Playgroud)

替换工作但显然是在URL匹配后完成的.在此之前有没有办法改变路径?

man*_*uel 9

显然,URL游行不是使用request.path但是request.path_info.改变此变量的相同中间件有效.