Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python django基于类的视图不接受视图参数和视图参数_Python_Django_Django Views_Django Middleware - Fatal编程技术网

Python django基于类的视图不接受视图参数和视图参数

Python django基于类的视图不接受视图参数和视图参数,python,django,django-views,django-middleware,Python,Django,Django Views,Django Middleware,我正在使用django 1.8。我在一个视图中使用了django.views.generic.View类 class CommonView(View): func_name = 'view_func' http_method_names = ["get", "post"] def get(self, request, *args, **kwargs): return render(request, 'template.html', {}) 在url.py

我正在使用django 1.8。我在一个视图中使用了
django.views.generic.View

class CommonView(View):
    func_name = 'view_func'
    http_method_names = ["get", "post"]
    def get(self, request, *args, **kwargs):
        return render(request, 'template.html', {})
在url.py中,我添加了

url(r'^common/$',CommonView),
我已经编写了一个中间件,其中我正在使用view-response和重写
process\u-view
方法进行一些工作

class CommonMiddleware(object):
    def process_view(self, request, view_func, view_args, view_kwargs):
        response = view_func(request, *view_args, **view_kwargs)
        """ Do something"""
        return response
但是在这一行中,
response=view\u func(请求,*view\u args,**view\u kwargs)
我得到了一个错误

__init__() takes exactly 1 argument (3 given)
Request Method: POST
Request URL:    http://127.0.0.1:8000/common/
Django Version: 1.8
Exception Type: TypeError
Exception Value:    
__init__() takes exactly 1 argument (3 given)

在此之前,我必须检查查看函数的
func\u name
。但是在中间件类中,当我试图从<代码> VisualFunc < /代码>中获得<代码>函数名>代码>时,我得到了<代码>属性错误 >代码>普通视图没有属性函名< />代码>,而我从所有基于函数的视图中得到它。p> 错误在这一行

url(r'^common/$',CommonView),
你必须使用

url(r'^common/$',CommonView.as_view()),

当您从URL调用基于类的视图时,忘记将
添加为\u view()
,这是一个愚蠢的错误。花了几个小时来查找错误。