我在Django装饰器(@save_post_request
)中使用request.POST.get('...')
,每当我的表单提交时,我都会遇到同样的错误
(错误为request.<anything>
):
AttributeError: 'collectData' object has no attribute 'POST'
我的decorator是在post()
classBasedView中的CollectData
函数之上调用的。你知道吗
#views.py
class collectData(View):
template_name = 'collect_data.html'
context = {...}
def get(self, request, *args, **kwargs):
...
return render(request, self.template_name, self.context)
@save_post_request
def post(self, request, *args, **kwargs):
...
return redirect(reverse('collectData'))
#decorators.py
def save_post_request(function):
def wrap(request, *args, **kwargs):
title = request.POST.get('title') # <---
...
return function(request, *args, **kwargs)
wrap.__doc__ = function.__doc__
wrap.__name__ = function.__name__
return wrap
我不确定是否可以使用classBasedViews
这样调用装饰程序,但我认为应该是正确的,我的错误是什么?你知道吗
内部函数的第一个参数应该是
self
:相关问题 更多 >
编程相关推荐