为什么Django Class Based视图会给__init __()的参数数量错误提供错误?

时间:2014-07-20 07:37:09

标签: python django django-views

我有一个非常基本的Django基于类的视图如下。它甚至没有做任何事情:

from django.views.generic import View, TemplateView

class index(TemplateView):
    template_name = 'myApp/index.html'

    def dispatch(self, request, *args, **kwargs):
        return super(index, self).dispatch(request, *args, **kwargs)

但是,当我通过浏览器加载此视图时,出现以下错误:

Exception Type: TypeError
Exception Value:    
__init__() takes exactly 1 argument (2 given)
Exception Location: /Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/core/handlers/base.py in get_response, line 112
Python Executable:  /usr/bin/python
Python Version: 2.7.5
Python Path:    

为什么我收到此错误?以及如何解决它?

下面是关于错误位置的更多背景信息:

/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/core/handlers/base.py in get_response
106.                    response = middleware_method(request, callback, callback_args, callback_kwargs)
107.                    if response:
108.                        break
109.            if response is None:
110.                wrapped_callback = self.make_view_atomic(callback)
111.                try:
112.                    response = wrapped_callback(request, *callback_args, **callback_kwargs) ...
113.                except Exception as e:
114.                    # If the view raised an exception, run it through exception
115.                    # middleware, and if the exception middleware returns a
116.                    # response, use that. Otherwise, reraise the exception.
117.                    for middleware_method in self._exception_middleware:
118.                        response = middleware_method(request, e)

0 个答案:

没有答案