【发布时间】:2018-09-10 05:41:02
【问题描述】:
我想使用包含正斜杠的参数调用 Django URL。例如,我想用'test1/test2' 打电话给mysite.com/test/。 (例如,天真地,url 应该是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 是正斜杠的标准 URL 编码)
出现以下错误:
错误:
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
【问题讨论】:
-
你能发表你的看法吗?
标签: python django django-2.0