django查询参数与空格

时间:2016-08-24 16:32:16

标签: python django url query-parameters

我有一个URL,它接受可能包含空格的查询参数。我知道它看起来很简单,但我的正则表达式对我不起作用。

这是我的网址格式定义:

url(
    r'^item_info_details_view/(?P<itemno>[\w \/&-]+)/$',
    'purchasing.views.item_info_details_view'),  

itemno可以是包含空格的FAX MODEM之类的短语。

但是,当我将这样的参数传递给它时,浏览器中的URL是

http://localhost/item_info_details_view/FAX%20MODEM/

并显示此调试信息:

Using the URLconf defined in urls, Django tried these URL patterns, in this order:
^$
The current URL, item_info/FAX MODEM/, didn't match any of these.

1 个答案:

答案 0 :(得分:0)

问题似乎不是空间,而是你在urlconf中有“item_info_details_view”而在实际网址中有“item_info”。

(由@ daniel-roseman撰写)