我收到以下错误消息:我尝试打开网址:
Request Method: GET
Request URL: http://localhost:8000/core/jmc/material/generate
Django Version: 1.8
Exception Type: AttributeError
Exception Value: 'bool' object has no attribute 'user'
Exception Location: /usr/local/lib/python2.7/dist-packages/django/contrib/auth/decorators.py in _wrapped_view, line 21
此外回溯如下所示:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
132. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/decorators.py" in _wrapped_view
22. return view_func(request, *args, **kwargs)
File "/home/dev/Documents/Program Codes/Python/Django/Zeus2/core/project/jmc.py" in jmc_material_generator
168. jmc_material_generator(False)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/decorators.py" in _wrapped_view
21. if test_func(request.user):
我的观点如下:
@login_required(login_url='login')
def jmc_material_generator(request):
# Permission level check
if request.user.groups.all()[0].name not in ['Super-Admin', 'Admin']:
return redirect('index')
with transaction.atomic():
jmc_material_generator(False)
return redirect('index')
答案 0 :(得分:0)
您的视图函数名称与第8行(jmc_material_generator(False)
)上调用的函数相同。这反过来再次调用您的视图函数并传入布尔值而不是请求对象。您需要重命名视图功能,或在将jmc_material_generator(False)
导入到view.py
文件时将其重命名。
# you can do import x as X which renamed the imported function
from ... import jmc_material_generator as jmc_generator
@login_required(login_url='login')
def jmc_material_generator(request):
# Permission level check
if request.user.groups.all()[0].name not in ['Super-Admin', 'Admin']:
return redirect('index')
with transaction.atomic():
jmc_generator(False) # notice the rename of this function
return redirect('index')