【发布时间】:2019-04-04 12:40:13
【问题描述】:
我正在使用 Django 获取 RedirectView,我想知道如何在我的 url 中传递一个 slug。
在我的 Django Web 应用程序中,用户可以在购物车中设置一个或多个文档,然后打开带有个人信息的模式,然后提交表单并收到一封包含已检查文档的电子邮件。
我的应用程序中的这个 url 看起来像这样:
http://localhost:8000/freepub/home?DocumentChoice=<code>&DocumentSelected=Add+document
<code> 对应一个唯一的文档代码(例如:PUBSD15-FR-PDF 或 PUBSD01-EN-EPUB)
但是这个url有点复杂,因为它应该添加到另一个应用程序中。
这就是为什么我使用RedirectView 来简化这个网址:
url(r'^freepub/direct/download/(?P<code>[\w\.-]+)/',
RedirectView.as_view(url="http://localhost:8000/freepub/home?DocumentChoice=(?P<code>[\w\.-]+)&DocumentSelected=Add+document"),
name='go-to-direct-download')
问题:
如果我写在我的网址中:http://localhost:8000/freepub/direct/download/PUBSD15-FR-PDF
重定向是:http://localhost:8000/freepub/home?DocumentChoice=(?P<code>[%5Cw%5C.-]+)&DocumentSelected=Add+document
如何在我的网址中考虑 code 而不是 (?P<code>[%5Cw%5C.-]+) ?
谢谢
【问题讨论】:
标签: regex django django-urls