我想用包含正斜杠的参数调用Django URL。例如,我想与mysite.com/test/
联系'test1/test2'
。 (例如,天真地,网址将是mysite.com/test/test1/test2
)
urls.py
:
urlpatterns = [
path('test/<test_arg>/', views.test, name='test'),
]
访问以下任一情况失败:
mysite.com/test/test1/test2
mysite.com/test/test1%2Ftest2
(%2F是正斜杠的标准网址编码)出现以下错误:
错误:
Using the URLconf defined in test.urls, Django tried these URL patterns, in this order:
reader/ test/<test_arg>/
admin/
The current path, test/test1/test2/, didn't match any of these.
我希望使用1中的路径失败,但我很惊讶2中的路径失败。
解决这个问题的正确方法是什么?
使用Django 2.0.2