django 报错“ init() takes 1 positional argument but 2 were given “
作者:互联网
报错" init() takes 1 positional argument but 2 were given "
- 解决:在App的
urls.py
文件中添加as_view()
方法
urlpatterns = [
path('', views.ArticleList.as_view(), name='list'),
]
如果继续报错:" AttributeError: ‘function’ object has no attribute ‘as_view’ "
- 可能是装饰器出问题了,比如在类视图上使用了
@api_view
装饰器,但这个装饰器是用于函数视图的 - 由于当时我是用的视图集,get、post等方法都在
ModelViewSet
中封装好了,装饰器是多此一举
标签:given,takes,argument,视图,报错,器是,装饰,view 来源: https://blog.csdn.net/qq_43510829/article/details/115429355