TypeError: got an unexpected keyword argument ‘id‘
程序员文章站
2022-06-13 10:03:14
...
我一开始使用的是正则表达式传参
url('^delete_books/(?P<id>.*?)/$', views.delete_books),
显然这样写是没有问题的,在views中接收这个参数
def delete_books(request,book_id):
b = BookInfo.objects.get(id=int(book_id))
b.delete()
return redirect('/total_books/')
这样写就会报错误,因为参数传不过来,也无法执行,直接报错
然后试了一下*args和**kwargs,前面一个我试了返回的是一个元组接收不到值。而**kwargs返回来了一个字典正好接收到!
def delete_books(request, *args, **kwargs):
b = BookInfo.objects.get(id=int(kwargs['id']))
b.delete()
return redirect('/total_books/')
此时就可以正常接收到参数了
上一篇: JS浏览器数据库
推荐阅读
-
报错解决Python Error fix-TypeError: _mean() got an unexpected keyword argument ‘dim‘
-
login() got an unexpected keyword argument 'extra_context'
-
TypeError: softmax() got an unexpected keyword argument 'axis' 解决办法
-
Django报错:TypeError: render() got an unexpected keyword argument 'renderer'
-
TypeError: login() got an unexpected keyword argument 'template_name'
-
TypeError: filter() got an unexpected keyword argument
-
解决 报错 TypeError: interleave() got an unexpected keyword argument ‘deterministic‘
-
TypeError: __init__() got an unexpected keyword argument 'shape'
-
Django TypeError: render() got an unexpected keyword argument 'renderer'
-
TypeError: got an unexpected keyword argument ‘id‘