在不使用替换方法的情况下,在django中未剥夺已久的文本
from django.utils.text import slugify
urlparameter = slugify("This is my First trip")
# this-is-my-first-trip
现在我要它解开它 对于以前的文本('这是我的第一次旅行'),但不使用替换。(“ - ”,“”)
是否有任何Django的方法?
from django.utils.text import slugify
urlparameter = slugify("This is my First trip")
# this-is-my-first-trip
now i want it to un-slugify it
to previous text ('this is my first trip') but not using replace.("-", " ")
Is there any django way to do so ??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有设计,没有设计。
slugify不是徒函数,例如,您不能总是从输出中回到输入。
例如,
如果您试图将“ ab”转回原始文本,那是哪一个?
如果您的sl源的来源受到非常控制的控制,请替换(“ - ”,“”)可能对您有用,或者您使用
urllib.parse.Quote.Quote
和urllib.parse.unquote可能会更好
https://docs.pypython.org/3/library/3/library/ urllib.parse.html
No built in way to do it, by design.
slugify is not a bijective function, e.g. you can't always get back to the input from the output.
e.g.
If you were trying to turn "a-b" back into orig text, which one is it?
If source of your slugs is very controlled then replace("-", " ") may work for you, or you may be better with
urllib.parse.quote
andurllib.parse.unquote
https://docs.python.org/3/library/urllib.parse.html