对所有下一个参数进行urlencode是否方便? - django [英] is it convenient to urlencode all next parameters? - django

查看:111
本文介绍了对所有下一个参数进行urlencode是否方便? - django的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在编写代码时,请求具有附加下一个查询字符串参数的页面是很常见的。

While writing code, it is pretty common to request a page with an appended "next" query string argument.

例如,在下面的模板代码中,接下来回到用户所在的页面:

For instance, in the following template code next points back to the page the user is on:

<a href="{%url some_view%}?next={{request.get_full_path}}

这里我遵循一个约定:如果下一个功能是我不能控制的,比如用户键入的搜索关键字,我urlencode它,否则我不会。 p>

Here I am following a convention: if next features something that I'm not in control of, such as search keywords a user has typed, I urlencode it. Otherwise I don't.

<a href="{%url some_view%}?next={{request.get_full_path|urlencode}}

代替对每个下一个参数进行判断,不管用户是否提供,是否方便,如果我urlencode字符串?会有副作用吗?目前我看不到什么?

Instead of judging for each next argument whether it would be user provided or not, would it be convenient if I urlencode all next strings? Will there be side effects I don't see at the moment?

推荐答案

据我所知, url应该是urlencoded。

To the best of my knowledge anything that's inside of a url should always be urlencoded.

唯一的问题是您需要确保在读取参数时反转编码。 django很可能已经为你做这个了。我需要查阅文档和/或代码以确认。

The only gotcha is that you need to make sure to reverse the encoding when you read in the arguments. It's very possible that django already does this for you. I'd need to consult the documentation and/or code to confirm though.

这篇关于对所有下一个参数进行urlencode是否方便? - django的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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