简体   繁体   English

如何在Django URL中用-替换%20

[英]How to replace %20 with - in django urls

I have a url which contains %20 . 我有一个包含%20的网址。 I want to replace it with - with the help of regex 我想将其替换为-在正则表达式的帮助下

I already tried replace method 我已经尝试过替换方法

url(r'^timeanalysis/(?P<name>[\w|\W]+)'.replace('%20','-'), timeseries.timeanalysis, name='timeanalysis')

I don't want to change my database. 我不想更改数据库。

This is something you need to fix at the point you generate the link, not in the urlconf. 这是您需要在生成链接时而不是在urlconf中修复的问题。

Usually you would use a SlugField that is automatically pre-populated from the title/name, replacing spaces with dashes as necessary. 通常,您会使用从标题/名称自动预填充的SlugField ,并在必要时用破折号代替空格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM