修改Django中间件的地址 [英] Modify address in Django middleware

查看:152
本文介绍了修改Django中间件的地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道是否可能,但是我想在URL的末尾添加几个参数,使用中间件。在modyfing请求的URL之后,可以不重定向吗?

I don't know if it's possible but I'd like to add few parameters at the end of the URL using middleware. Can it be done without redirect after modyfing requested URL?

ie。
用户点击:... / some_link
和中间件将其重写为:... / some_link?par1 = 1& par2 = 2

ie. user clicks: .../some_link and middleware rewrites it to: .../some_link?par1=1&par2=2

其他方法是修改响应并替换每个HTML链接,但这不是我想要做的。

Other way is to modify reponse and replace every HTML link but it's not something I'd like to do.

谢谢

推荐答案

我觉得这真的取决于你的问题,你究竟想要做什么。

I think this really depends on your problem and what exactly you are trying to do.

你不能改变URL而不重定向用户,因为您无法在没有重新加载的情况下修改页面上的URL。基本上,重定向是一个响应,告诉用户继续前进,没有办法实际更改URL。请注意,即使您像JavaScript这样做,您基本上做同样的重定向,所以它不能完成客户端或服务器端。

You cannot change the URL without redirecting the user, as you cannot modify the URL on a page without a reload. Basically a redirect is a response telling the user to move on, there is no way to actually change the URL. Note that even if you do it in something like JavaScript you basically do the same as a redirect, so it can't be done client or server side.

我认为如果您向我们解释为什么需要通过URL传递此信息,可能会有所帮助。为什么不在会话中存储数据?

I think it might help if you explain to us why you need to pass this information via the URL. Why not store data in the session?

我想你可以将数据添加到请求对象,但不会将其添加到URL。

I guess you could add the data to the request object but that doesn't add it to the URL.

这篇关于修改Django中间件的地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆