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中封装好了,装饰器是多此一举
上一篇:Maven : 将Jar安装到本地仓库和Jar上传到私服[转]


下一篇:Linux服务器大量log日志查看命令,快速定位错误