我组成如下的urlpatterns。

url(r'^sktag/(?P<st_char>\w+)/$', views.MW_Tag_Search.as_view(), name='tagSearch')


我在Chrome浏览器中输入了网址。

http://localhost:8000/common/sktag/Engineer(SW)


然后我找不到页面。参考以下

Using the URLconf defined in MW_Service.urls, Django tried these URL patterns, in this order:
1. ^common/ ^sktag/(?P<st_char>\w+)/exclude/(?P<ex_tags>\w+[\+\w+]*)/$ [name='tagSearchV2']
2. ^common/ ^sktag/(?P<st_char>\w+)/$ [name='tagSearch']
...
The current URL, common/sktag/Engineer(SW), didn't match any of these.


我认为'('或')'字符会导致此问题,但我不知道如何解决。

最佳答案

您指定的模式末尾需要一个'/'才能匹配。

http://localhost:8000/common/sktag/Engineer(SW)/
应该管用。

编辑:

您还需要更新正则表达式以处理括号。有关更多详细信息,请参考Python Regular Expressions 文档。

关于python - 找不到页面(404),Django中的URL映射,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32239936/

10-10 19:06