python - django url反向隐藏关键字参数

标签 python django django-views

考虑来自此 url /messages/compose/(?P<recipients>[\+\.\w]+)/ 的请求其中收件人是用 + 分隔的用户名符号。成功后(成功发送给收件人的消息)我正在做:

#success_url = 'message_send_success'
recipients = '+'.join([obj.username for obj in recipients]) #converting them back to original string
reverse(success_url, kwargs={'recipients': recipients})

这是它匹配的网址:

url(r'^/messages/success/(?P<recipients>[\+\.\w]+)$', 'site.views.message_send_success', name='message_send_success')

但它会显示网址中的所有收件人,我是否可以隐藏要在网址中显示的那些收件人字符串并可以在请求中访问它?

最佳答案

也许您想使用 base64 库:

>>> base64.b64encode("what is that?")
'd2hhdCBpcyB0aGF0Pw=='
>>> base64.b64decode("d2hhdCBpcyB0aGF0Pw==")
'what is that?'

注意:如果您想要更多安全网址,您应该对该字符串进行一些翻译(否则知道基本(en)编码的其他用户将轻松解码您的值。

关于python - django url反向隐藏关键字参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10790952/

相关文章:

Python:引用大小?

Django admin - 如果编辑对象,则删除字段

Django 查询使用 and 子句

python - 为什么 ListView 不显示模板中的数据?

python - 使用 python/COM 的 Windows 应用程序自动化

Python tree.iterparse 导出所选元素(包括所有后代)的源 XML

python - 我如何遍历对象的字段?

python - 我将如何打包和销售 Django 应用程序?

python - makemigration 导致错误 "TypeError: expected str, bytes or os.PathLike object, not NoneType"

django - 为什么 DEBUG=False 设置会使我的 django 静态文件访问失败?