我的项目中有以下URL配置Django
:
urlpatterns = [
path('', views.record_create),
path('<entry_method>/', views.record_create, name = "record_create"),
]
视图去:
def record_create(request, entry_method="bulk/"):
在我的模板中,我这样做:
<a href="{% url "record_create" entry_method=request.path_info %}">
我收到以下错误:
django.urls.exceptions.NoReverseMatch: Reverse for 'record_create' with keyword arguments '{'entry_method': '/bulk/'}' not found. 1 pattern(s) tried: ['(?P<entry_method>[^/]+)/$']
不知道我在做什么错。欢迎任何建议。
问题不在于反向查找。问题在于,您entry_method
在url模式中默认情况下是str
路径转换器,而不是path
。您可以使用以下方法设置参数的类型:
urlpatterns = [
path('', views.record_create),
path('<path:entry_method>', views.record_create, name = "record_create"),
]
有关更多信息,请参见有关路径转换器的文档[Django-doc]。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句