HI从django url 调用端点时出错
这是我的一段javascript
window.location.assign(`customer/?id=1`}
我的网址.py
path('customer/(?P<int:id>d+)', views.get_customer, name="get_customer")
以下是它在视图中的调用方式.py
def get_customer(request, id):
print(f"the id {id}")
# # customer = get_object_or_404(Customer, pk=id)
# # print(f"customer {customer}")
其想法是通过作为查询参数传递的id来过滤客户记录但我收到一个错误
Using the URLconf defined in inventorymanagement.urls, Django tried these URL patterns, in this order:
admin/
[name='home']
customer/(?P<int:id>d+) [name='get_customer']
The current path, customer/, didn’t match any of these.
你知道怎么解决这个问题吗?
urls.py中的路径与您在windows.location中设置的url不匹配。。。试试这个:
window.location.assign('customer/1')
Django文档中关于在url中使用Regexp的一些示例:https://docs.djangoproject.com/en/4.1/topics/http/urls/#using-正则表达式