Django And Django-Rest-Framework 异常记录

  • 时间:
  • 来源:互联网
  • 文章标签:

1.TypeError: init() takes 1 positional argument but 2 were given

异常信息 :

[14/Feb/2017 11:29:51] "GET /dataAPI/ed/farm HTTP/1.1" 301 0
Internal Server Error: /dataAPI/ed/farm/
Traceback (most recent call last):
  File "E:\Anaconda3\lib\site-packages\django\core\handlers\exception.py", line 39, in inner
    response = get_response(request)
  File "E:\Anaconda3\lib\site-packages\django\core\handlers\base.py", line 249, in _legacy_get_response
    response = self._get_response(request)
  File "E:\Anaconda3\lib\site-packages\django\core\handlers\base.py", line 187, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "E:\Anaconda3\lib\site-packages\django\core\handlers\base.py", line 185, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
TypeError: __init__() takes 1 positional argument but 2 were given
[14/Feb/2017 11:29:51] "GET /dataAPI/ed/farm/ HTTP/1.1" 500 69874

解决:
Django Rest Framework 开发api , 使用class ,配置 url 忘记 as_view() !!!!

Example :

class FarmList(APIView):
    def get(self, request, format=None):
        return Response(serializer.data)

url 配置 需要 as_view()

urlpatterns = [
    url(r'^farm/$', views.FarmList.as_view()),
]

本文链接http://www.taodudu.cc/news/show-647405.html