这是我的代码:
class MobileMiddleware(object):
def process_request(self, request):
if request.path.startswith('/core/mypage/'):
request.path='/core/mypage/?key=value'
print request.path,'aaaa'
我想在页面 url 为 /core/mypage/
时添加一个参数 key
,
并且网络浏览器的 url 将更改为 http:www.ss.com/core/mypage/?key=value
但是,浏览器中的 url 并没有改变。
我能做什么?
最佳答案
对于 googlers - 我使用 request.path_info 进行了测试。如果您想更改中间件中的 URL,请更改 process_request 中的 request.path_info .
request.path_info = <change request.path_info>
请注意,我不建议或禁止使用它。我只是说如果您想更改 URL,这就是您可以的方式。
关于python - 如何使用 django process_request 更改 url。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6366589/